无法安装Python包

12 投票
4 回答
6348 浏览
提问于 2025-04-16 10:28

我刚接触CentOS,想在上面安装M2Crypto这个Python包。

我执行了:

sudo python setup.py install

看起来一切都很顺利:(这是输出的最后部分)

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

但是我却无法导入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
>>> 

我哪里出错了呢?

4 个回答

2

我刚遇到同样的问题,在centos 6.2上。

运行测试也帮我解决了这个问题。不过当我查看网站包的时候,发现没有任何变化。运行setup.py test会在本地目录中构建m2crypto。

这就是问题的关键,要解决这个问题而不运行setup.py test,就要离开M2Crypto文件夹。因为它是从本地文件夹中获取m2crypto,而不是找到那个蛋包。

4

tests当成目标是不对的,应该用test来代替;这样就解决了我的问题。

6

我运行了:

python setup.py tests

然后问题就解决了。它复制了一些文件,我觉得这让库文件放到了正确的位置。

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
.
.
.

撰写回答