[英]Jupyter and conda: error when cloning environment
我創建了多個 conda 環境以測試已安裝軟件包的兼容性。 我使用conda create -n test02 --clone test01
創建環境 test02 作為 test01 的克隆。 我激活 test02,安裝新包並啟動 python 實例,從中導入新包沒有問題。 當我啟動 jupyter notebook 或 qtconsole 並嘗試導入新安裝的包並出現導入錯誤時出現問題:沒有名為“xxx”的模塊。 我做了一個sys.executable
並看到 jupyter 正在從舊環境(test01)運行 python 我從中克隆了新環境。 為什么會這樣? 我可以在某個地方的配置文件中更改它嗎?在哪里可以找到這個文件?
編輯:更多信息
jupyter --paths
兩個環境共享同一環境目錄中配置和數據的路徑條目
(test01) PS C:\Users\Aka> jupyter --paths
config:
C:\Users\Aka\.jupyter
c:\users\aka\miniconda3\envs\test01\etc\jupyter
C:\ProgramData\jupyter
data:
C:\Users\Aka\AppData\Roaming\jupyter
c:\users\aka\miniconda3\envs\test01\share\jupyter
C:\ProgramData\jupyter
runtime:
C:\Users\Aka\AppData\Roaming\jupyter\runtime
(test01) PS C:\Users\Aka> conda activate test02
(test02) PS C:\Users\Aka> jupyter --paths
config:
C:\Users\Aka\.jupyter
c:\users\aka\miniconda3\envs\test01\etc\jupyter
C:\ProgramData\jupyter
data:
C:\Users\Aka\AppData\Roaming\jupyter
c:\users\aka\miniconda3\envs\test01\share\jupyter
C:\ProgramData\jupyter
runtime:
C:\Users\Aka\AppData\Roaming\jupyter\runtime
編輯 2:我忘了提到我使用 pip 安裝了 Jupyter。
重現我所做的問題:
conda create -n env1
conda activate env1
pip install jupyter
jupyter --paths
配置:
C:\\Users\\Aka.jupyter
c:\\users\\aka\\miniconda3\\envs\\env1\\etc\\jupyter
C:\\ProgramData\\jupyter
數據:
C:\\Users\\Aka\\AppData\\Roaming\\jupyter
c:\\users\\aka\\miniconda3\\envs\\env1\\share\\jupyter
C:\\ProgramData\\jupyter
運行:
C:\\Users\\Aka\\AppData\\Roaming\\jupyter\\runtime
conda create --clone env1 -n env2
conda activate env2
jupyter --paths
配置:
C:\\Users\\Aka.jupyter
c:\\users\\aka\\miniconda3\\envs\\env1\\etc\\jupyter
C:\\ProgramData\\jupyter
數據:
C:\\Users\\Aka\\AppData\\Roaming\\jupyter
c:\\users\\aka\\miniconda3\\envs\\env1\\share\\jupyter
C:\\ProgramData\\jupyter
運行:
C:\\Users\\Aka\\AppData\\Roaming\\jupyter\\runtime
如果我將帶有 conda 的 jupyter 安裝到一個全新的環境中,然后克隆該環境,則 jupyter 會按預期運行。 注意:我使用 pip 安裝了 jupyter,因為我使用的是 python 3.5,因為我需要其他軟件包,並且在我的環境中使用 conda 安裝 jupyter 不斷破壞它。 我向 conda-forge 尋求幫助,但他們說“對不起,我們不支持 python 3.5”。
Jupyter 只需要安裝在一個位置 - Conda 環境或系統級別。
要將其他環境用作內核,需要使用nb_conda_kernels
在環境中安裝 nb_conda_kernels,並在您希望用作內核的任何ipykernel
中安裝nb_conda_kernels
。 始終使用jupyter notebook
從 env 啟動jupyter notebook
,其他的將自動可用。
如果 Jupyter 安裝在系統級別,則必須手動注冊希望用作內核的 Conda 環境:
conda activate my_env
conda install ipykernel
python -m ipykernel install --user --name my_env_name
然后從任何地方啟動 Jupyter。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.