4

I run Python Scripts on our Dreamhost Server. Our Python scripts use Python 2.7 - we made a custom installation because Dreamhost uses Python 2.6. Everything worked fine for 1 year.

Dreamhost did a server update yesturday and now our scripts fail to find a specific module - MD5. The scripts output the error below when we go to import hashlib.

What do I need to do to rectify this?

  • Should I reinstall Python 2.7?
  • Should I reinstall Pip and Easy_Install?
  • Should I reinstall VirtualEnv?
  • Is there something else you recommend I do?

Error from all Python scripts:

/home/user/script.py in () 
  import hashlib  
  hashlib undefined    

/home/user/python/lib/python2.7/hashlib.py in ()  
    # version not supporting that algorithm.  
    try:  
        globals()[__func_name] = __get_hash(__func_name)  
    except ValueError:  
        import logging builtin globals = <built-in function globals, __func_name = 'md5', __get_hash = <function __get_builtin_constructor  /home/user/python/lib/python2.7/hashlib.py in __get_builtin_constructor(name='md5')  
        return _sha.new  
    elif name in ('MD5', 'md5'):  
        import _md5  
         return _md5.new  
     elif name in ('SHA256', 'sha256', 'SHA224', 'sha224'):  
 _md5 undefined  

<type 'exceptions.ImportError': No module named _md5  
   args = ('No module named _md5',)  
   message = 'No module named _md5' 
sazr
  • 24,984
  • 66
  • 194
  • 362
  • Quite possibly that libssl was updated and maybe some references broke. Run `ldd /path/to/your/python2.7` to see whether it is properly linked to libssl. Really though, you should at least try reinstalling python2.7 at first. Alternatively check whether the base system that dreamhost now uses comes with python2.7 instead. – metatoaster Oct 07 '14 at 02:30

1 Answers1

5

I was having the exact same issue. I run Python 2.7 in my own virtualenv. I am trying to avoid reinstalling python and run a Django 1.7 application.

The following approach works for me.

STEP 1. (This step might not be necessary)

I uninstalled pythonbrew since it says here: http://wiki.dreamhost.com/Python that pythonbrew has been deprecated. If you were doing this from scratch pyenv is way to go, but you don't need to reinstall virtualenv, etc. Just get rid of pythonbrew to start with.

$ rm -Rf ~/.pythonbrew

Removed references in .bashrc to pythonbrew

STEP 2.

There is no need to re-install virtualenv. Just create a new virtual env

$~/env> virtualenv myNewEnvironment
$~/env/myNewEnvironment/bin> source activate
$ pip freeze

You have a clean slate now, start rebuilding dependencies from scratch. At least is solves the "import hashlib" issue. This gives you a clean version of python properly linked to the new Ubuntu OS.

(myNewEnvironment):~> which python
~/env/myNewEnvironment/bin/python
(myNewEnvironment):~> python
Python 2.7.3 (default, Feb 27 2014, 19:58:35)  
[GCC 4.6.3] on linux2
installed on Ubuntu 12.04 (which is the new OS)

Verify: import hashlib should not throw error

STEP 3.

pip install Django
pip install MySQL-python

Its also probably safer to complete/recheck the remaining steps listed out in http://wiki.dreamhost.com/Django (or appropriate wiki page for your framework)

For now this allows me to get my site up and running, (but) there is a warning that I am ignoring for now until I figure out more: You have unapplied migrations; your app may not work properly until they are applied. Run 'python manage.py migrate' to apply them.

Good luck!

kramamurthi
  • 299
  • 1
  • 4
  • 1
    I'll add the caveat that, for me, virtualenv _itself_ also failed with the md5 error until I removed my custom python from the path. – clearf Oct 10 '14 at 05:21