当前位置: 动力学知识库 > 问答 > 编程问答 >

ImportError from non-standard Python even though module exists

问题描述:

We have a setup based on CentOS 6.4 but with Python 2.7 (due to historical reasons). Note that CentOS 6 brings Python 2.6. Python 2.7 has been compiled from a Fedora 20 SRPM. In addition, to make it possible to freely use Python RPMs from CentOS 6 along with the 2.7 interpreter, we have created a /usr/lib/python2.7/site-packages/setup.pth file with the contents:

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

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

Things used to work fine till the need to use protobuf-python-2.3.0-9.el6.x86_64 arose. This RPM has been downloaded from the EPEL repo and is available: 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

One thing that could be helpful is that the import error does not come with 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

This error does not come with other import statements (e.g. import pip.vcs). It is somehow related to protobuf-python. What could be the reason? Any insight will be appreciated.

EDIT: The protobuf-python RPM installs files into /usr/lib/python2.6/site-packages/google/protobuf and the the 2.7 interpreter's sys.path is:

$ /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']

分享给朋友:
您可能感兴趣的文章:
随机阅读: