[英]Installed packages with pip are not shown in pip freeze?
I'm using virtualenv
and pip
on Debian Wheezy. 我在Debian Wheezy上使用
virtualenv
和pip
。 I'm having an odd problem where packages appear to install OK, but then aren't visible in the virtualenv. 我有一个奇怪的问题,包似乎安装好,但然后在virtualenv中不可见。
This is my requirements.txt
file: 这是我的
requirements.txt
文件:
Django==1.7.7
psycopg2==2.5.4
django-geojson==2.6.0
If I install it with pip
from inside my virtualenv, it says everything has been installed: 如果我从我的virtualenv内部用
pip
安装它,它说已经安装了所有东西:
(.venv)$ sudo pip install -r requirements.txt
Requirement already satisfied (use --upgrade to upgrade): Django==1.7.7 in /usr/local/lib/python2.7/dist-packages (from -r requirements/base.txt (line 1))
Requirement already satisfied (use --upgrade to upgrade): psycopg2==2.5.4 in /usr/local/lib/python2.7/dist-packages (from -r requirements/base.txt (line 2))
Requirement already satisfied (use --upgrade to upgrade): django-geojson==2.6.0 in /usr/local/lib/python2.7/dist-packages (from -r requirements/base.txt (line 3))
Requirement already satisfied (use --upgrade to upgrade): six in /usr/local/lib/python2.7/dist-packages (from django-geojson==2.6.0->-r requirements/base.txt (line 3))
Cleaning up...
But then if I do pip freeze
to check what is installed, it looks like pip
thinks I have a completely different set of packages, and in particular it doesn't see djgeojson
there: 但是如果我做
pip freeze
以检查安装的内容,看起来pip
认为我有一套完全不同的软件包,特别是它没有看到djgeojson
:
(.venv)$ pip freeze
Django==1.7.4
argparse==1.2.1
coverage==3.7.1
distribute==0.6.24
django-debug-toolbar==1.2.1
gunicorn==19.3.0
psycopg2==2.5.4
requirements==0.1
setproctitle==1.1.8
sqlparse==0.1.14
wsgiref==0.1.2
And if I fire up a Python terminal, Python can't see djgeojson
. 如果我启动一个Python终端,Python就看不到
djgeojson
。
Why is this happening? 为什么会这样? It is quite confusing.
这很令人困惑。
Your problem is that you've installed requirements with sudo and they were installed in your system python library folder instead and not in your virtual environment's venv
library. 您的问题是您已经安装了sudo的需求,而且它们安装在您的系统python库文件夹中,而不是安装在虚拟环境的
venv
库中。
What to do? 该怎么办? Run the same command but this time without sudo:
pip install -r requirements.txt
. 运行相同的命令,但这次没有sudo:
pip install -r requirements.txt
。 This will run pip from the virtual environment and install packages to the right place. 这将从虚拟环境运行pip并将软件包安装到正确的位置。
When you activate a virtual environment eq with source path/to/my/venv/bin/acivate
the path variable $PATH
of your current user is updated and then when you run something with sudo, this new $PATH that you've just updated when activating the virtual environment is no longer the same. 当您使用
source path/to/my/venv/bin/acivate
激活虚拟环境eq时,会更新当前用户的路径变量$PATH
,然后当您使用sudo运行某些内容时,您刚刚更新了这个新的$ PATH激活虚拟环境时不再相同。 Same thing happens when you open a new shell window or logs in as a different user with su
or running sudo
, $PATH
variable is not a global system one. 当您打开一个新的shell窗口或以
su
或运行sudo
作为其他用户登录时,会发生同样的事情, $PATH
变量不是全局系统变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.