与virtualenvs和Python软件包的混淆
在我的python程序(使用python3.5由virtualenv运行)中,我需要使用Pillow库来处理图像.
In my python program (run by a virtualenv using python3.5), I need to use the Pillow library to process an image.
ImportError:没有名为枕头"的模块
ImportError: No module named 'Pillow'
告诉我在virtualenv中未安装枕头.
tells me that Pillow is not installed in the virtualenv.
但是,当我运行pip install Pillow
时,我会回来:
But, when I run pip install Pillow
, I get back:
已经满足要求:放在/usr/lib/python3/dist-packages中
Requirement already satisfied: Pillow in /usr/lib/python3/dist-packages
如果我正在使用的pip
来自virtualenv,那么为什么要在/usr/lib/python3/dist-packages
中查找以检查软件包是否已安装?
If the pip
I am using is from the virtualenv, then why is it looking in /usr/lib/python3/dist-packages
to check if the package is already installed?
仅需确保,我运行type python
和type pip
来确认这两个程序来自我的virtualenv,它们分别是:
Just to make sure, I run type python
and type pip
to confirm that these 2 programs are from my virtualenv, and they are:
python被散列了(/home/nelson/.virtualenvs/MainEnv/bin/python)
python is hashed (/home/nelson/.virtualenvs/MainEnv/bin/python)
pip进行了哈希处理(/home/nelson/.virtualenvs/MainEnv/bin/pip)
pip is hashed (/home/nelson/.virtualenvs/MainEnv/bin/pip)
创建virtualenv时不使用
sudo
(我知道,因为这已经给我造成了问题)或尝试pip install
时,未使用
sudo
;那么,这种逻辑的缺陷在哪里呢?如何在我的virtualenv中安装枕头/如何导入枕头?
sudo
was not used when creating the virtualenv (I know because this had already caused problems for me) or when trying to pip install
; so where is the flaw in this logic? How can I install Pillow in my virtualenv / How can I import Pillow?
如果使用--system-site-packages
创建了虚拟环境,则该虚拟环境可以访问全局站点程序包模块.
If you created the virtual environment with --system-site-packages
, the virtual environment has access to the global site-packages modules.
如果您不想这样做,则需要重新创建不带--system-site-packages
选项的虚拟环境.
You need to re-create the virtual environment without --system-site-packages
option if you don't want that.