我的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
提前感谢您的帮助。