【发布时间】:2018-12-01 22:19:17
【问题描述】:
我的sys.path 遇到了一个奇怪的问题;因为我要清楚地描述这个问题,所以这篇文章会有点长。
我的/usr/lib/python2.7/site-packages/easy-install.pth 看起来像这样:
import sys; sys.__plen = len(sys.path)
./setuptools-27.2.0-py2.7.egg
./jmespath-0.9.3-py2.7.egg
./chardet-3.0.4-py2.7.egg
./certifi-2018.01.18-py2.7.egg
./urllib3-1.22-py2.7.egg
./requests-2.18.4-py2.7.egg
./docutils-0.14-py2.7.egg
./python_dateutil-2.7.5-py2.7.egg
./enum34-1.1.6-py2.7.egg
./six-1.10.0-py2.7.egg
./ipaddress-1.0.18-py2.7.egg
./asn1crypto-0.22.0-py2.7.egg
./idna-2.6-py2.7.egg
./pyOpenSSL-17.2.0-py2.7.egg
/usr/lib64/python2.7/site-packages/cryptography-2.0.3-py2.7-linux-x86_64.egg
/usr/lib64/python2.7/site-packages/cffi-1.10.0-py2.7-linux-x86_64.egg
import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:]; p=getattr(sys,'__egginsert',0); sys.path[p:p]=new; sys.__egginsert = p+len(new)
有了这些东西对我来说很好;具体来说,pyOpenSSL 的正确版本包含在我的sys.path 中:
[root@sandbox ~]# python -c "import OpenSSL; print OpenSSL.__version__"
17.2.0
当我删除第一行和最后一行时,python 命令我的pyOpenSSL 版本会发生变化;这意味着当我的easy-install.pth 看起来像这样时:
./setuptools-27.2.0-py2.7.egg
./jmespath-0.9.3-py2.7.egg
./chardet-3.0.4-py2.7.egg
./certifi-2018.01.18-py2.7.egg
./urllib3-1.22-py2.7.egg
./requests-2.18.4-py2.7.egg
./docutils-0.14-py2.7.egg
./python_dateutil-2.7.5-py2.7.egg
./enum34-1.1.6-py2.7.egg
./six-1.10.0-py2.7.egg
./ipaddress-1.0.18-py2.7.egg
./asn1crypto-0.22.0-py2.7.egg
./idna-2.6-py2.7.egg
./pyOpenSSL-17.2.0-py2.7.egg
/usr/lib64/python2.7/site-packages/cryptography-2.0.3-py2.7-linux-x86_64.egg
/usr/lib64/python2.7/site-packages/cffi-1.10.0-py2.7-linux-x86_64.egg
那么pyOpenSSL 版本是旧版本:
[root@sandbox ~]# python -c "import OpenSSL; print OpenSSL.__version__"
0.13.1
我认为这是因为这里存在旧版本的 pyOpenSSL /usr/lib64/python2.7/site-packages/pyOpenSSL-0.13.1-py2.7.egg-info
所以我的第一个问题是:easy-install.pth 中的这些命令在做什么?easy-install.pth 是如何处理来更改我的sys.path 的?
接下来是当我尝试使用easy_install(来自他们的源代码)安装新的python包时,它破坏了我的easy-install.pth——在某种意义上所有包仍然存在但没有第一行和最后一行(那些python 命令)。
更具体地说:我正在尝试安装idna-2.5,它确实安装成功但搞砸了easy-install.pth
[root@sandbox idna-2.5]# easy_install .
Processing .
Writing /opt/proj/sbs-installs/COSpkgs/idna-2.5/setup.cfg
Running setup.py -q bdist_egg --dist-dir /opt/proj/sbs-installs/COSpkgs/idna-2.5/egg-dist-tmp-sLNbiE
warning: no previously-included files matching '*.pyc' found under directory 'tools'
warning: no previously-included files matching '*.pyc' found under directory 'tests'
zip_safe flag not set; analyzing archive contents...
Removing /usr/lib/python2.7/site-packages/idna-2.5-py2.7.egg
Moving idna-2.5-py2.7.egg to /usr/lib/python2.7/site-packages
Removing idna 2.6 from easy-install.pth file
Adding idna 2.5 to easy-install.pth file
Installed /usr/lib/python2.7/site-packages/idna-2.5-py2.7.egg
Processing dependencies for idna==2.5
Finished processing dependencies for idna==2.5
注意它卸载了idnz 2.6。在这之后我的easy-install.pth 看起来像这样:
./setuptools-27.2.0-py2.7.egg
./jmespath-0.9.3-py2.7.egg
./chardet-3.0.4-py2.7.egg
./certifi-2018.01.18-py2.7.egg
./urllib3-1.22-py2.7.egg
./requests-2.18.4-py2.7.egg
./docutils-0.14-py2.7.egg
./python_dateutil-2.7.5-py2.7.egg
./enum34-1.1.6-py2.7.egg
./six-1.10.0-py2.7.egg
./ipaddress-1.0.18-py2.7.egg
./asn1crypto-0.22.0-py2.7.egg
./pyOpenSSL-17.2.0-py2.7.egg
/usr/lib64/python2.7/site-packages/cryptography-2.0.3-py2.7-linux-x86_64.egg
/usr/lib64/python2.7/site-packages/cffi-1.10.0-py2.7-linux-x86_64.egg
./idna-2.5-py2.7.egg
现在当我检查 pyOpenSSL 版本时,它是旧版本(如上所述):
[root@sandbox ~]# python -c "import OpenSSL; print OpenSSL.__version__"
0.13.1
提前感谢您的帮助。
【问题讨论】:
-
那么下一个问题是:为什么
easy_install会从easy-install.pth中删除那些python 命令?
标签: python-2.7 installation setuptools easy-install