Getting setuptools/easy_install to play nicely with PYTHONPATH
Why do setuptools/easy_install .pth files not place nicely with PYTHONPATH, and how do I get them to play nicely, and keep the directories in my PYTHONPATH before those .pth shoves in the sys.path?
My current problem is I've created a package for our project, with the both PyYAML and PyCrypto as requirements.
install_requires=["PyYAML",
"pycrypto >= 2.3"]
As we've been developing, we've installed PyYaml in the standard directory (/usr/lib64/python2.6/site-packages) with pip. We installed an older version of PyCrypto in there, then discovered we needed the newer one, which we installed under /opt/devtools/lib64/python2.6/site-packages. We've had already been setting our PYTHONPATH to read from /opt first, before /usr/lib64. And that all worked fine in development. When we ran, we got PyCrypto 2.3 from /opt, and PyYaml from /usr/lib64/....
But now, when I'm trying installing in a virtualenv, and when I run python setup.py develop
, setuptools/distribute ends up adding /usr/lib64/python2.6/site-packages to the easy-install.pth, but not /opt/devtools/lib64/python2.6/site-packages. It's finding the right versions, as seen in the output:
Using 开发者_运维问答/home/s3447/projects/wsrs.git/emp_parsing
Searching for pycrypto==2.3
Best match: pycrypto 2.3
Adding pycrypto 2.3 to easy-install.pth file
Using /opt/wsrs-devtools/stow/pycrypto-2.3/lib64/python2.6/site-packages
Searching for PyYAML==3.10
Best match: PyYAML 3.10
Adding PyYAML 3.10 to easy-install.pth file
But not adding /opt/... to the easy-install.pth. (Only /usr/lib64... and the directory I ran setup.py in is added to the path.)
The end result is, although I setuptools thinks it was successfully, when I run my code, easy-install.pth decides it knows what I want better than I do, inserts itself before my PYTHONPATH, and I end up importing the wrong version of PyCrypto.
Two questions:
Why is setuptools inconsistent about which directories it adds to the .pth file? I would expect either both directories or neither directory to be installed.
Is there any way to get setuptools to not try to override my PYTHONPATH? Why was that even considered a good idea in the first place?
From what I understand of your question, this may be where to take your concerns about that: https://github.com/pypa/setuptools/issues/397
Sounds like others have had a similar problem. I could be wrong, I just use pip. I never use easy_install if I can help it.
精彩评论