【发布时间】:2020-05-06 05:14:33
【问题描述】:
我创建了多个 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
edit2:我忘了提到我使用 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”。
【问题讨论】:
-
你安装了ipykernel吗?还有,启动jupyter的时候,新建notebook的时候可以选择新环境(test02)吗(点击new下拉,有的话选择test02)?
-
是的,已安装 ipykernel。从笔记本应用程序的下拉菜单中创建新笔记本时,没有选择环境的选项或指示。
-
我认为问题在于 conda 环境需要在为它们创建内核之前被激活。这是 Jupyter 不做的事情。
-
@carlosCordoba,这不是问题所在。问题在于,当新环境处于活动状态并从该环境启动 jupyter 应用程序时,路径指向另一个环境。
标签: python pip jupyter-notebook conda conda-forge