即使模块存在,也会从非标准Python导入ImportError

时间:2015-09-27 19:03:54

标签: python python-2.7 centos6 python-2.6

我们有基于CentOS 6.4但使用Python 2.7的设置(由于历史原因)。请注意,CentOS 6 brings Python 2.6。 Python 2.7是从Fedora 20 SRPM编译的。此外,为了能够从CentOS 6和2.7解释器中自由使用Python RPM,我们创建了一个包含内容的/usr/lib/python2.7/site-packages/setup.pth文件:

/usr/lib64/python2.6/site-packages
/usr/lib/python2.6/site-packages

在需要使用protobuf-python-2.3.0-9.el6.x86_64之前,事情一直很好。此RPM已从EPEL回购中下载并可用:here

$ /usr/bin/python2.7
Python 2.7.4 (default, Mar 17 2015, 00:48:39) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import google.protobuf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named google.protobuf

可能有用的一件事是Python 2.6没有导入错误:

$ /usr/bin/python
Python 2.6.6 (r266:84292, Jan 22 2014, 09:42:36) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import google.protobuf

其他导入语句(例如import pip.vcs)未附带此错误。它与protobuf-python有某种关联。可能是什么原因?任何见解都将受到赞赏。

编辑:protobuf-python RPM将文件安装到/usr/lib/python2.6/site-packages/google/protobuf,而2.7解释程序的sys.path是:

$ /usr/bin/python2.7 -c 'import sys; print sys.path' | sed -e 's/,/\n/g'
[''
 '/usr/lib64/python27.zip'
 '/usr/lib64/python2.7'
 '/usr/lib64/python2.7/plat-linux2'
 '/usr/lib64/python2.7/lib-tk'
 '/usr/lib64/python2.7/lib-old'
 '/usr/lib64/python2.7/lib-dynload'
 '/usr/lib64/python2.7/site-packages'
 '/usr/lib/python2.7/site-packages'
 '/usr/lib64/python2.6/site-packages'
 '/usr/lib/python2.6/site-packages']

0 个答案:

没有答案