virtualenv 不使用自己的包
我开始在我的项目中使用 virtualenv 和 virtualenvwrapper 。
使用 workon
命令激活 virtualenv 后,我使用 pip install -U
安装了以下软件包:
$ lssitepackages
django pip
Django-1.3-py2.7.egg-info pip-1.0.1-py2.7.egg-info
easy-install.pth setuptools-0.6c11-py2.7.egg
fabric setuptools.pth
Fabric-1.0.1-py2.7.egg-info south
geopy South-0.7.3-py2.7.egg-info
geopy-0.94.1-py2.7.egg-info
这里的问题是(在激活 virtualenv 的情况下运行命令) :
$ whereis python
python: /usr/bin/python2.6 /usr/bin/python /usr/bin/python2.7 /etc/python2.6 /etc/python /etc/python2.7 /usr/lib/python2.6 /usr/lib/python2.7 /usr/lib64/python2.6 /usr/lib64/python2.7 /usr/local/lib/python2.6 /usr/local/lib/python2.7 /usr/include/python2.6 /usr/include/python2.7 /usr/share/python /usr/share/man/man1/python.1.gz
$ whereis django-admin
django-admin: /usr/bin/django-admin /usr/local/bin/django-admin.py /usr/share/man/man1/django-admin.1.gz
$ whereis fab
fab: /usr/local/bin/fab
我的 virtualenv 它没有使用本地包!
如何强制 virtualenv 使用本地 Python 和本地版本的 packges 而不是我的机器包?
更新 - 可能的解决方案
我使用 mkvirtualenv --no-site-packages
创建了一个新的 virtualenv,现在我得到了这些输出:
$ which python
/home/user/.virtualenvs/VIRTUALENVNAME/bin/python
$ which django-admin
/usr/bin/django-admin
$ which django-admin.py
/home/user/.virtualenvs/VIRTUALENVNAME/bin/django-admin.py
$ which fab
/home/user/.virtualenvs/VIRTUALENVNAME/bin/fab
听起来好像现在正在工作..除了“django-admin”命令。
I'm starting to use virtualenv and virtualenvwrapper on my projects.
After activating the virtualenv with the workon
command, i installed the following packages with pip install -U <package>
:
$ lssitepackages
django pip
Django-1.3-py2.7.egg-info pip-1.0.1-py2.7.egg-info
easy-install.pth setuptools-0.6c11-py2.7.egg
fabric setuptools.pth
Fabric-1.0.1-py2.7.egg-info south
geopy South-0.7.3-py2.7.egg-info
geopy-0.94.1-py2.7.egg-info
The problem here is (running commands with the virtualenv activated):
$ whereis python
python: /usr/bin/python2.6 /usr/bin/python /usr/bin/python2.7 /etc/python2.6 /etc/python /etc/python2.7 /usr/lib/python2.6 /usr/lib/python2.7 /usr/lib64/python2.6 /usr/lib64/python2.7 /usr/local/lib/python2.6 /usr/local/lib/python2.7 /usr/include/python2.6 /usr/include/python2.7 /usr/share/python /usr/share/man/man1/python.1.gz
$ whereis django-admin
django-admin: /usr/bin/django-admin /usr/local/bin/django-admin.py /usr/share/man/man1/django-admin.1.gz
$ whereis fab
fab: /usr/local/bin/fab
My virtualenv it's not using the local packages!
How do I force the virtualenv use local Python and local version of packges instead my machine packages?
Update - Possible solution
I created a new virtualenv with mkvirtualenv --no-site-packages <name>
and now I got these outputs:
$ which python
/home/user/.virtualenvs/VIRTUALENVNAME/bin/python
$ which django-admin
/usr/bin/django-admin
$ which django-admin.py
/home/user/.virtualenvs/VIRTUALENVNAME/bin/django-admin.py
$ which fab
/home/user/.virtualenvs/VIRTUALENVNAME/bin/fab
Sounds like it's working now... except for the "django-admin" command.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用以下命令安装 virtualenv:
创建没有任何外部 python 库的 virtualenv
try install the virtualenv using:
to create the virtualenv without any external python libraries
您使用两个不同的命令来查找正在使用的 Python 版本。第一次使用“whereis”,第二次使用“which”。 “whereis”不是您想要用来识别哪个版本将在您的环境中运行的命令。
来自“whereis”的手册页:
最后一行在这里很重要。 whereis“尝试在标准 Linux 位置列表中找到所需的程序。”当您使用 virtualenv 时,该版本的 Python 不在标准 Linux 位置。
使用“which”来代替,就像你第二次做的那样。摘自“which”的手册页:
这就是您要用来识别将在您的 virtualenv 中运行的 Python 版本的那个。
You're using two different commands to locate which Python version is being used. The first time, you used "whereis" and the second time you used "which". "whereis" is not the command you want to use to identify which version will run in your environment.
From the man pages of "whereis":
This last line is important, here. whereis "attempts to locate the desired program in a list of standard Linux places." When you're using a virtualenv, that version of Python is not in a standard Linux place.
Use "which" instead, like you did the second time. Excerpt from the man pages of "which":
That's the one you want to use to identify which version of Python will run in your virtualenv.