简体   繁体   English

带有install_requires的setup.py开发会将dist-packages放在virtualenv的sys.path顶部

[英]`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-packagesmock所在的地方)。 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 的源代码 ,这似乎是有意的。

Question

Is there anyway to disable it messing with the position of dist-packages in my sys.path ? 无论如何,有没有禁用它,使dist-packagessys.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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM