【发布时间】:2019-10-26 07:04:48
【问题描述】:
我有一个 virtualenvwrapper 包装的 virtualenv。我们称之为测试。 Jupyter 是通过我的全局 pip 和 virtualenv 的 pip 安装的。
$ which python
/usr/bin/python
$ which pip
/usr/local/bin/pip
$ which jupyter
/usr/local/bin/jupyter
$ workon test
(test)$ which python
/home/keon/.virtualenvs/test/bin/python
(test)$ which pip
/home/keon/.virtualenvs/test/bin/pip
(test)$ which jupyter
/home/keon/.virtualenvs/test/bin/jupyter
现在,我通过 /usr/local/bin/pip 安装了包 A,通过 /home/keon/.virtualenvs/test/bin/pip 安装了包 B。 (astropy 和 emcee resp.,但我不认为这很重要)
我启动 jupyter notebook(在测试 virtualenv 的 shell 中)。然后我在一个单元格中运行此代码:
import astropy
import emcee
: 并得到以下错误
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-12-43214a4612e2> in <module>()
1 import astropy
----> 2 import emcee
ImportError: No module named 'emcee'
在单元格中,我使用 !外壳命令:
!which python
!which pip
!which jupyter
!echo "Pip freeze below:\n---------------------"
!pip freeze
输出是
/home/keon/.virtualenvs/ph20/bin/python
/usr/local/bin/pip
/usr/local/bin/jupyter
Pip freeze below:
---------------------
[snip]
astropy==3.0.3
所以我的 python 是 virtualenv 的,但它似乎正在使用全局 jupyter 和 pip。
这个问题似乎只存在于我的一个虚拟环境中。如果我使用不同的,运行前面描述的相同单元格,输出符合预期:
/home/keon/.virtualenvs/test2/bin/python
/home/keon/.virtualenvs/test2/bin/pip
/home/keon/.virtualenvs/test2/bin/jupyter
【问题讨论】:
标签: python pip jupyter-notebook virtualenv virtualenvwrapper