13

I have python 2.5.1 installed on my Ubuntu 10.04 x86_64 machine.

When i try to import hashlib/md5, the i get this error

>>> import hashlib 
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.5/hashlib.py", line 133, in <module>
md5 = __get_builtin_constructor('md5')
File "/usr/local/lib/python2.5/hashlib.py", line 60, in __get_builtin_constructor
import _md5
ImportError: No module named _md5

I have tried most of the solutions that I could find on google, but nothing works for me. Does anyone know how to solve this? Thank you!

Chaos
  • 11,213
  • 14
  • 42
  • 69
  • Did you build this Python yourself, or does it come from `apt-get`? – Fred Foo Apr 24 '12 at 21:53
  • 1
    I downloaded the .tar file from the site and then ./configure, make and make install – Chaos Apr 24 '12 at 21:54
  • Sorry, I should have known from the `/usr/local` in the error message. – Fred Foo Apr 24 '12 at 22:00
  • 4
    This is probably due to an incompatible OpenSSL libraries in your install that's causing the python to not build `md5` (which is normally used) and not building `_md5` (which is built if OpenSSL wasn't found). Is there a reason that you want to build your own rather than using ubuntu's? – wkl Apr 24 '12 at 22:01
  • no, there's no specific reason for me to use my own, so how do I undo what I've installed so that i can install using apt-get? – Chaos Apr 24 '12 at 22:04
  • 1
    http://stackoverflow.com/questions/3544378/uninstall-python-built-from-source – Fred Foo Apr 24 '12 at 22:05
  • You don't need to install via apt-get, Ubuntu 10.04 should already have python installed in `/usr/bin` unless you did something very weird. You can try running `/usr/bin/python`. – wkl Apr 24 '12 at 22:14
  • yeah, i guess i just complicated things by installing my own python, i just undid whatever i did, and everything's back to normal, thanks guys! – Chaos Apr 24 '12 at 23:20
  • 2
    @birryree I am facing the same issue. I don't have root privileges, so I can't update the openssl package. I donloaded its(libssl-dev) source code and compiled it. Now how can I make sure that if I build python, it uses this newly generated libraries and not the one's in system? – Rahul Sep 17 '13 at 19:39

1 Answers1

8

You have to have the package libssl-dev installed before configuring and compiling python from the tarball:

sudo apt-get install libssl-dev
cd YOUR_PYTHON_2.5_1_SRC_DIR
make clean
./configure
make
sudo make install

Do you have a good reason not to use the latest version in the 2.5.X series?

Anthon
  • 69,918
  • 32
  • 186
  • 246