[英]`setup.py develop` with `install_requires` puts `dist-packages` at top of `sys.path` in virtualenv
I have a directory ~/foo
and all it has is setup.py
which contains: 我有一个目录
~/foo
,它只有setup.py
,其中包含:
from setuptools import setup, find_packages
setup(
name='foo',
version='0.1',
packages=find_packages(),
install_requires=['mock']
)
Now, I create a virtual environment using: 现在,我使用以下方法创建虚拟环境:
cd ~
virtualenv --system-site-packages v1
And doing ~/v1/bin/python -c "import sys; print sys.path"
, I get 然后做
~/v1/bin/python -c "import sys; print sys.path"
,我得到
['',
'/home/garrett',
'/home/garrett/v1/lib/python2.7',
'/home/garrett/v1/lib/python2.7/plat-x86_64-linux-gnu',
'/home/garrett/v1/lib/python2.7/lib-tk',
'/home/garrett/v1/lib/python2.7/lib-old',
'/home/garrett/v1/lib/python2.7/lib-dynload',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/home/garrett/v1/local/lib/python2.7/site-packages',
'/home/garrett/v1/lib/python2.7/site-packages',
'/usr/local/lib/python2.7/site-packages',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/PILcompat',
'/usr/lib/python2.7/dist-packages/gtk-2.0',
'/usr/lib/pymodules/python2.7',
'/usr/lib/python2.7/dist-packages/ubuntu-sso-client']
but, when I do 但是,当我这样做
sudo pip install mock
cd ~/foo
~/v1/bin/python setup.py develop
then setuptools changes my virtualenv's sys.path
to have dist-packages
(where mock
lives) near the top. 然后,setuptools将我的virtualenv的
sys.path
更改为在顶部附近有dist-packages
( mock
所在的地方)。 Ie, the first 3 entries of sys.path
become: 即,
sys.path
的前3个条目变为:
['',
'/usr/local/lib/python2.7/dist-packages',
'/home/garrett/foo',
...
This seems intentional from looking at the source which modifies easy-install.pth
. 通过查看修改
easy-install.pth
的源代码 ,这似乎是有意的。
Is there anyway to disable it messing with the position of dist-packages
in my sys.path
? 无论如何,有没有禁用它,使
dist-packages
在sys.path
的位置混乱? My dist-packages
directory has other modules in it which are been given unwanted precedence. 我的
dist-packages
目录中有其他模块,这些模块被赋予了不必要的优先级。
不确定这是否是最佳解决方案,但是阻止setuptools赋予dist_packages
更高优先级的一种方法是添加--always-copy
标志。
~/v1/bin/python setup.py develop --always-copy
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.