天天看點

更好地使用Atom支援基于Jupyter的Python開發

有關于使用Atom進行Python開發的網上資料比較少,最近發現使用Atom結合Hydrogen插件進行Python開發,尤其是資料挖掘相關的工作,整體體驗要好于Vscode,Vscode雖然說也有連接配接Jupyter的工具,但是互動式的開發Hydrogen體驗更好。

這裡放了個動圖來展示一下Hydrogen的強大

更好地使用Atom支援基于Jupyter的Python開發

插件安裝

Python

  • Hydrogen
  • atom-ide-ui
  • ide-python

這裡要注意,本地的pip需要 安裝 python-language-server[all],在ide-python的readme中有詳細說明

遠端連接配接

  • Remote FTP

美化

  • simplified-chinese-menu(漢化更新檔)
  • file-icons(檔案夾圖示)
  • bracket-colorizer(彩虹括号,找了好久,确定就是必須配合暗色主題)
  • atom-bracket-highlight(括号高亮)
  • atom-clock(加個時鐘在右下角)
  • highlight-selected(高亮選擇)
  • minimap(類似sublime的右側map欄)
  • minimap-highlight-selected(選擇代碼後,map上也高亮,友善定位代碼)

插件配置

這裡先講一下我的需求,我是需要利用其連接配接公司伺服器上的内容,但是公司伺服器是需要跳闆機的,是以我需要通過跳闆機才能通路,是以配置上會有些複雜

{
    "protocol": "sftp",
    "host": "跳闆機域名", // string - Hostname or IP address of the server. Default: 'localhost'
    "port": 跳闆機端口, // integer - Port number of the server. Default: 22
    "user": "使用者名", // string - Username for authentication. Default: (none)
    "pass": "如果用密鑰這裡就不用填", // string - Password for password-based user authentication. Default: (none)
    "promptForPass": false, // boolean - Set to true for enable password/passphrase dialog. This will prevent from using cleartext password/passphrase in this config. Default: false
    "remote": "實際的伺服器目錄,例如:/伺服器域名/使用者名/目錄", // try to use absolute paths starting with /
    "agent": "", // string - Path to ssh-agent's UNIX socket for ssh-agent-based user authentication. Linux/Mac users can set "env" as a value to use env SSH_AUTH_SOCK variable. Windows users: set to 'pageant' for authenticating with Pageant or (actual) path to a cygwin "UNIX socket." Default: (none)
    "privatekey": "本地私鑰path", // string - Absolute path to the private key file (in OpenSSH format). Default: (none)
    "passphrase": "", // string - For an encrypted private key, this is the passphrase used to decrypt it. Default: (none)
    "hosthash": "", // string - 'md5' or 'sha1'. The host's key is hashed using this method and passed to the hostVerifier function. Default: (none)
    "ignorehost": true,
    "connTimeout": 10000, // integer - How long (in milliseconds) to wait for the SSH handshake to complete. Default: 10000
    "keepalive": 10000, // integer - How often (in milliseconds) to send SSH-level keepalive packets to the server (in a similar way as OpenSSH's ServerAliveInterval config option). Set to 0 to disable. Default: 10000
    "keyboardInteractive": 如果要用動态令牌,這裡就要填true, // boolean - Set to true for enable verifyCode dialog. Keyboard interaction authentication mechanism. For example using Google Authentication (Multi factor)
    "keyboardInteractiveForPass": false, // boolean - Set to true for enable keyboard interaction and use pass options for password. No open dialog.
    "remoteCommand": "",
    "remoteShell": "",
    "watch":[],
    "watchTimeout":500, // integer - The duration ( in milliseconds ) from when the file was last changed for the upload to begin.
}
           

需要配置一下

Python Executable

填寫你的python路徑,比如使用的是conda虛拟環境,就這樣寫

/xxx/anaconda3/envs/xxx/bin/python

連接配接本地Kernel

首先需要在上面填寫的路徑下的python環境中安裝

ipykernel

python -m ipykernel install --user --name py37

然後用atom打開一個py檔案,輸入

# %%
print('hello atom')

# %%
print('每一個# %%代表一個新的cell')
           

然後再第2行末尾按ctrl+enter就會自動彈出來讓你選擇環境的彈窗,選擇剛剛建立的環境即可

更好地使用Atom支援基于Jupyter的Python開發

連接配接遠端Kernel

[{"name": "Remote server",
  "options": {
    "baseUrl": "jupyter url",
    "token": "jupyter token"
  }
}]
           
更好地使用Atom支援基于Jupyter的Python開發