[英]importing module behaves differently in Jupyter notebook and Interpreter?
[英]Change Interpreter in Jupyter notebook
我正在嘗試將 Jupyter 筆記本環境的解釋器路徑更改為與 PyCharm 一起使用的解釋器路徑。
當我使用 Jupyter 筆記本執行以下代碼時,我在 Anaconda 主文件夾中安裝了 python,而不是我與 PyCharm 一起使用的那個。
import sys
print(sys.executable)
使用哪個命令,我可以更改與 PyCharm 一起使用的其他 python 安裝的路徑?
我相信您正在尋找的是如何更改您正在運行的 Kernel。 如果您將 go 轉到 Jupyter 中的 Kernel 菜單,您將看到更改內核的選項。
如果要從 conda 環境添加新的 kernel,請終止 jupyter,激活要為其添加 kernel 的環境,然后運行此命令(需要conda install ipykernel
-- thx @shad):
python -m ipykernel install --user --name <kernel_name> --display-name "<Name_to_display>"
確保將<kernel_name>
和<Name_to_display>
替換為您的環境名稱。 此外,這需要您conda install ipykernel
(感謝@shad)。
安裝 kernel 后,您可以通過上面的菜單甚至通過 Jupyter 單元中的以下代碼片段進行更改:
%%javascript
Jupyter.notebook.session.restart({kernel_name: '<kernel_name>'})
首先激活您要使用的環境:
conda activate myenv
然后啟動jupyter:
jupyter notebook /path/to/your/dir
您還可以使用以下內容:
conda activate base
然后使用檢查jupyter的位置
type jupyter
如果它位於
~/anaconda3/bin/jupyter
那么你對 go 很好。 之后,您可以使用jupyter我在主機和服務器機器之間的 ssh 隧道中使用的是:
jupyter notebook --no-browser --port=1234
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.