简体   繁体   中英

Can't install a Python package

I'm very new to CentOS and I am trying to install the M2Crypto Python package on it.

I ran:

sudo python setup.py install

And it appeared to go ok: (this is the end of the output)

removing 'build/bdist.linux-i686/egg' (and everything under it)
Processing M2Crypto-0.20.2-py2.4-linux-i686.egg
Removing /usr/lib/python2.4/site-packages/M2Crypto-0.20.2-py2.4-linux-i686.egg
Copying M2Crypto-0.20.2-py2.4-linux-i686.egg to /usr/lib/python2.4/site-packages
M2Crypto 0.20.2 is already the active version in easy-install.pth

Installed /usr/lib/python2.4/site-packages/M2Crypto-0.20.2-py2.4-linux-i686.egg
Processing dependencies for M2Crypto==0.20.2

However I can't import M2Crypto:

$ python
Python 2.4.3 (#1, Nov 11 2010, 13:34:43) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import M2Crypto
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "M2Crypto/__init__.py", line 22, in ?
import __m2crypto
ImportError: No module named __m2crypto
>>> 

What am I doing wrong?

I ran:

python setup.py tests

and that fixed it. It copied some files, which I think resulted in the lib being put in the right place.

running test
running egg_info
writing M2Crypto.egg-info/PKG-INFO
writing top-level names to M2Crypto.egg-info/top_level.txt
writing dependency_links to M2Crypto.egg-info/dependency_links.txt
reading manifest file 'M2Crypto.egg-info/SOURCES.txt'
writing manifest file 'M2Crypto.egg-info/SOURCES.txt'
running build_ext
copying build/lib.linux-i686-2.4/M2Crypto/__m2crypto.so -> M2Crypto
test_BitSTring (tests.test_asn1.ASN1TestCase) ... ok
.
.
.

tests isn't a valid target, run test instead; that fixed the problem for me.

I just ran into the same issue, on centos 6.2.

Running test also fixed it for me. However when I looked in site packages, nothing was changed. Running setup.py test builds m2crpyto in the local directory.

That's the key to the problem, to fix the issue without running setup.py test, leave the M2Crypto folder. It's picking up m2crypto from the local folder, and not finding the egg.

This happens to me occasionally when installing python modules. There are a couple of things I do to resolve this issue:

  1. Sometimes it's because you never set your PYTHONPATH. Try:

    setenv PYTHONPATH /usr/lib/python2.4/site-packages:$PYTHONPATH

  2. Sometimes it's because of shared libraries found in /usr/lib and you would have to perform:

setenv LD_LIBRARY_PATH /usr/lib:$LD_LIBRARY_PATH

Let me know how this goes for you. Most of the time its just because you didn't set the python path correctly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM