Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 434
VacuumTube Avatar asked Jan 23 '11 11:01

VacuumTube


People also ask

Why Python Cannot install package?

Try to create another Python interpreter that is based on the Python version that meets the requirement. The package cannot be installed because you don't have permissions to install it. Try to install the package using super-user privileges, for example, sudo pip install <package name> .

Why can't I pip install on Python?

One of the most common problems with running Python tools like pip is the “not on PATH” error. This means that Python cannot find the tool you're trying to run in your current directory. In most cases, you'll need to navigate to the directory in which the tool is installed before you can run the command to launch it.

How can I install packages in Python?

To install a package that includes a setup.py file, open a command or terminal window and: cd into the root directory where setup.py is located. Enter: python setup.py install.


2 Answers

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
.
.
.
like image 74
VacuumTube Avatar answered Sep 27 '22 23:09

VacuumTube


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

like image 29
Simon Avatar answered Sep 28 '22 00:09

Simon