让 setuptools/easy_install 与 PYTHONPATH 完美配合
为什么 setuptools/easy_install .pth 文件不能很好地与 PYTHONPATH 放置在一起,以及如何让它们很好地发挥作用,并在 .pth 推入 sys.path 之前将目录保留在我的 PYTHONPATH 中?
我当前的问题是我已经为我们的项目创建了一个包,并满足 PyYAML 和 PyCrypto 的要求。
install_requires=["PyYAML",
"pycrypto >= 2.3"]
在我们开发过程中,我们使用 pip 将 PyYaml 安装在标准目录 (/usr/lib64/python2.6/site-packages) 中。我们在那里安装了旧版本的 PyCrypto,然后发现我们需要更新的版本,我们将其安装在 /opt/devtools/lib64/python2.6/site-packages 下。我们已经将 PYTHONPATH 设置为先从 /opt 读取,然后再读取 /usr/lib64。这一切在开发过程中都运行良好。当我们运行时,我们从 /opt 获得了 PyCrypto 2.3,从 /usr/lib64/.... 获得了 PyYaml。
但是现在,当我尝试在 virtualenv 中安装时,当我运行 python setup.pydevelop< /code>,setuptools/distribute 最终将 /usr/lib64/python2.6/site-packages 添加到 easy-install.pth,但不是/opt/devtools/lib64/python2.6/site-packages。它正在找到正确的版本,如输出所示:
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
但没有将 /opt/... 添加到 easy-install.pth 中。 (只有 /usr/lib64... 以及我运行 setup.py 的目录被添加到路径中。)
最终结果是,虽然我 setuptools 认为它是成功的,但当我运行我的代码时,easy-install.pth 决定它比我更清楚我想要什么,将自己插入到我的 PYTHONPATH 之前,最终我导入了错误版本的 PyCrypto。
两个问题:
为什么 setuptools 在添加到 .pth 文件的目录方面不一致?我希望安装两个目录或两个目录都不安装。
有什么方法可以让 setuptools 不尝试覆盖我的 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据我对你的问题的理解,这可能是你对此问题的担忧:
https://github.com/pypa/setuptools/issues/397
听起来像其他人有过类似的问题。我可能是错的,我只是使用pip。如果可以的话,我从不使用 easy_install。
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.