python using easy_install ImportError: No module named _md5 - python

I searched a lot and did not find any answer to this problem =(
I have a CentOS 5 as a server, following this How To:
http://wiki.osqa.net/display/docs/RHEL%2C+CentOS+5+Installation+Guide#RHEL%2CCentOS5InstallationGuide-Python
I'm able to install python 2.6 separated from the yum version. But when I run ./easy_install ElementTree I get this strange error:
Traceback (most recent call last):
File "./easy_install", line 9, in <module>
load_entry_point('distribute==0.6.14', 'console_scripts', 'easy_install')()
File "/opt/ActivePython-2.6/lib/python2.6/site-packages/pkg_resources.py", line 305, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/opt/ActivePython-2.6/lib/python2.6/site-packages/pkg_resources.py", line 2244, in load_entry_point
return ep.load()
File "/opt/ActivePython-2.6/lib/python2.6/site-packages/pkg_resources.py", line 1954, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "/opt/ActivePython-2.6/lib/python2.6/site-packages/setuptools/command/easy_install.py", line 24, in <module>
from setuptools.package_index import PackageIndex
File "/opt/ActivePython-2.6/lib/python2.6/site-packages/setuptools/package_index.py", line 2, in <module>
import sys, os.path, re, urlparse, urllib2, shutil, random, socket, cStringIO
File "/opt/ActivePython-2.6/lib/python2.6/urllib2.py", line 93, in <module>
import hashlib
File "/opt/ActivePython-2.6/lib/python2.6/hashlib.py", line 136, in <module>
md5 = __get_builtin_constructor('md5')
File "/opt/ActivePython-2.6/lib/python2.6/hashlib.py", line 63, in __get_builtin_constructor
import _md5
ImportError: No module named _md5
I do not understand python and have no idea how to fix this issue, I'm trying to install OSQA to run a phpBB support forum for another country.
Thanks for any help, best regard's.

My guess having had a similar issue on CentOS before, is that the ld path for the new Python isn't set, and it can't find its loadable modules folder.
The 3rd code block on this blog post shows setting an ld path for an opt Python (though it is 2.7): http://toey.tc20.net/2010/08/04/install-python-2-7-gevent-on-centos-5-x86_64/
I would assume that an installer would have done this as part of the install step, but maybe the blog post above will be of some help.

I had the same problem and found that the issue is unrelated to _md5.so, but instead that hashlib is failing to import _hashlib.so within a try block, then getting to a different and normally unused section of code (where the _md5 problem shows up). Try:
import _hashlib.so
I got something like:
ImportError: <PATH>/lib/python2.7/lib-dynload/_hashlib.so: cannot restore segment prot after reloc: Permission denied
I googled that and found http://www.quantumwise.com/forum/index.php?topic=16.0 which says you need to do:
chcon -t texrel_shlib_t <PATH>/lib/python2.7/lib-dynload/_hashlib.so
This worked for me.

Activepython 2.6 seems to have some problem in their latest build. please check for its former release.

I also encounter the same issue like you, I fix it after I add the lib path of python where the module will be installed.
It is really caused by LD_LIBRARY_PATH, please try to add "/opt/ActivePython-2.6/lib" into your LD_LIBRARY_PATH.
setenv LD_LIBRARY_PATH /opt/ActivePython-2.6/lib:$LD_LIBRARY_PATH

Credit to http://johnsofteng.wordpress.com/2009/06/21/python-importerror-no-module-named-_md5/
I met the similar problem on Redhat 6.4, python binary (2.7.x) packages is copied from other already installed system (which is built from source).
The problem is the _hashlib.so, which miss the libssl.so.0.9.8
bash-4.1# ldd /proj/application/tools/python2.7/lib/python2.7/lib-dynload/_hashlib.so
linux-vdso.so.1 => (0x00007fff51d6f000)
libssl.so.0.9.8 => not found
libcrypto.so.0.9.8 => /usr/lib64/libcrypto.so.0.9.8 (0x00007f9a69746000)
libpython2.7.so.1.0 => /proj/application/tools/python2.7/lib/libpython2.7.so.1.0 (0x00007f9a6936b000)
I just install missed package and soft link to the library.
bash-4.1# yum install -y tar openssh-clients
bash-4.1# ln -s /usr/lib64/libssl.so.0.9.8e /usr/lib64/libssl.so.0.9.8
Then the setuptool installation is successful

Related

No module named 'json' after installing simplejson

I am working in Ubuntu 14.04 and I have multiple versions of Python on my machine (they include python2.7 and python3.4). Few days back, I installed simplejson on my system. I don't remember how I did that but I guess it must be similar to pip install simplejson. However, now a strange problem has started appearing when I try installing any python package. For example, just now I tried installing Tkinter using sudo pip3.4 install Tkinter and it throws the following error:
Traceback (most recent call last):
File "/usr/local/bin/pip3.4", line 9, in <module>
load_entry_point('pip==1.5.4', 'console_scripts', 'pip3.4')()
File "/usr/lib/python3/dist-packages/pkg_resources.py", line 351, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python3/dist-packages/pkg_resources.py", line 2363, in load_entry_point
return ep.load()
File "/usr/lib/python3/dist-packages/pkg_resources.py", line 2088, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "/usr/lib/python3/dist-packages/pip/__init__.py", line 61, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "/usr/lib/python3/dist-packages/pip/vcs/subversion.py", line 4, in <module>
from pip.index import Link
File "/usr/lib/python3/dist-packages/pip/index.py", line 15, in <module>
from pip.wheel import Wheel, wheel_ext
File "/usr/lib/python3/dist-packages/pip/wheel.py", line 25, in <module>
from distlib.scripts import ScriptMaker
File "/usr/share/python-wheels/distlib-0.1.8-py2.py3-none-any.whl/distlib/scripts.py", line 15, in <module>
File "/usr/share/python-wheels/distlib-0.1.8-py2.py3-none-any.whl/distlib/resources.py", line 20, in <module>
File "/usr/share/python-wheels/distlib-0.1.8-py2.py3-none-any.whl/distlib/util.py", line 11, in <module>
ImportError: No module named 'json'
Sometimes I can fix this if the error tells me that in one of the files I have:
import json
which I simply convert to
import simplejson as json
I tried uninstalling simplejson:
sudo pip uninstall simplejson
but it gives me the same error: json not found.
Can anybody please help me fix this so that I would happily be able to install python packages? Thanks in advance.
Note: I do not have a definitive answer but will offer a series of steps you can try:
The first thing is see if you can import json from the usual python interpreter:
import json
print(json.__file__) #this would be important to know if it works
If that does work (as well as commenting what json.__file__ is) you would then want to try to use pip from the interpreter.
If you can't import json normally:
This is not surprising, I did not expect pip to be looking in a non-standard place for modules. You will want to figure out where the json package should be located on your computer, you can do this by importing another module from the standard library and looking at it's __file__:
>>> import fractions
>>> fractions.__file__
'/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/fractions.py'
This will obviously be different for you but I'd expect there to be a json folder in the same folder as fractions.py
if you can't import fractions or queue or datetime etc.
If you can't import anything from the standard library you will probably want to just reinstall python.
If the json folder is there and contains an __init__.py
Use the rename function of your file browser to make sure there are no weird special characters, but other then that I'm not sure, if you can import fractions.py but not a package from the same folder that would imply there is something very wrong with the import mechanics of your python version.
If the json folder is not with the rest of the standard library
It is possible that your python distribution has a different structure then I'd expect, it at least can't hurt to take a look for it.
You can search for the json folder amongst your various python files using the find command, not really sure how it works but just another thing to try. If you do find it with the __init__.py, encode.py, decode.py, scanner.py, and tool.py (at least those are the ones in my version) you'll probably want to figure out how it got there, but maybe just move it to the same folder as the rest of the standard library.
If you can't find the json package or you find it and it is corrupted
Well then you will need to replace it! Don't worry, this isn't too hard, just grab a source release of python from the site and extract the json package from it, once it is uncompressed the json folder should be in the Lib folder. Simply copy/move it to the rest of the standard library and you should be good to go!
I hope this helps you debug what is going on, This covers all the scenarios I could imagine happening and I would be interested in which one fixed your issue (or what you were able to figure out so I can come up with more options)
I am guessing that you install it using either pip install simplejson to download from PyPI or using apt-get install python-simplejson to download from ubuntu repositories.
It is possible that you downlaoded the library for the Python2 if you used any of the commands above and it won't be available for Python3 (which pip3.4 will use). Can you try these commands and help debug yourself?
$ python -c "import simplejson"
$ python3.4 -c "import simplejson"
This would tell you which version of the python did you install simplejson for last time (my guess in python2). If the 2nd command errors out with ImportError try:
$ pip3.4 install simplejson
and then install your libraries.

Ckan install module missing error

I am attempting to install ckan on my system and I'm following the install from package directions (http://docs.ckan.org/en/latest/maintaining/installing/install-from-package.html). All the dependencies were installed correctly and the ckan package itself downloaded without error. When I went to run the install I got a module missing error for what to me looks like a trivial python module that should be there.
jeremy#jeremy-HP-ProBook-4530s:~$ sudo dpkg -i python-ckan_2.5-trusty_amd64.deb
[sudo] password for jeremy:
(Reading database ... 214293 files and directories currently installed.)
Preparing to unpack python-ckan_2.5-trusty_amd64.deb ...
Unpacking python-ckan (2.5.1-trusty1) over (2.5.1-trusty1) ...
Setting up python-ckan (2.5.1-trusty1) ...
Traceback (most recent call last):
File "/usr/lib/ckan/default/bin/paster", line 7, in <module>
from paste.script.command import run
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/paste/script/command.py", line 3, in <module>
import pkg_resources
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 36, in <module>
import plistlib
File "/usr/lib/python2.7/plistlib.py", line 62, in <module>
import datetime
ImportError: No module named datetime
/var/lib/dpkg/info/python-ckan.postinst: line 18: initctl: command not found
Site datapusher already enabled
I've confirmed that datetime is installed with a quick python -c 'import datetime' run. At this point I have done a little bit of digging and haven't been able to find anywhere else where this is duplicated nor exactly how to resolve this. Any help or advice is greatly appreciated.
Looking around for the error from plistlib it looks like the same error affecting https://bugs.launchpad.net/ubuntu/+source/python2.7/+bug/1368144
Unfortunately I'm not sure how this would have come about. I'll continue digging and see if I can find out more, but it isn't anything I've seen before but it definitely appears virtualenv related.

Installing Scipy Error in Windows 7

In a round about way, I corrupted my scipy/numpy installation on my IntelX64/Windows 7/Python 2.7 computer. I did this by trying to play around with some neural network libraries (lasagne/theano).
To fix this, I completely removed/reinstalled python 2.7.9. After that, I went to http://www.lfd.uci.edu/~gohlke/pythonlibs/ to download and install numpy and scipy with commands:
pip install C:\Users\me\Documents\numpy-1.9.2+mkl-cp27-none-win_amd64.whl
This went well and succeeded. (I can import numpy from python)
pip install C:\Users\me\Documents\scipy-0.15.1-cp27-none-win_amd64.whl
This appeared to go well too. Except the error occurs in the python console:
>>> from scipy import stats
Gives:
Traceback (most recent call last):
File "<stdin>", line1, in <module>
File "C:\Python27\lib\site-packages\scipy\stats\__init__.py", line 338, in <module>
from .stats import *
File "C:\Python27\lib\site-packages\scipy\stats\stats.py", line 184, in <module>
import scipy.special as special
File "C:\Python27\lib\site-packages\scipy\special\__init__.py", line 586, in <module>
from ._ufuncs import *
ImportError: DLL load failed: The specified module could not be found.
I read up on the DLLs required and ran the 'dependency walker' (http://www.dependencywalker.com/) on "c:\python27\lib\site-packages\scipy\special_UFUNCS.PYD" and it seems there are a few DLL files not found.
libifcoremd.dll
libiomp5md.dll
libmmd.dll
msvcr90.dll
dcomp.dll
ieshims.dll
and a 6 files that look like 'api-ms-win-....dll'
From my looking around, people have solved this by reinstalling numpy, then scipy. I have tried that and the same thing occurs.
Has anyone else run into this issue and solved it?
I fixed this by a complete removal of everything (python and packages) and then installing everything again.
Just reinstalling the offending packages did not work. Neither did system restore. I will not accept this answer, because removing/installing is a work around to the real problem. I just want to post this to help anyone else in this position.
Simply install 'NumPy-1.9+MKL' from this page, it should work fine.
Acknowledgement: Another post here :)

"OSError: dlopen(libSystem.dylib, 6): image not found" (OS X + macports + Celery 3.1.7)

I just updated celery via pip (1.5) to the latest version (3.1.7), but I get a fatal exception which I don't understand as soon I try to import the library. By running:
from celery import Celery in the shell I get:
File "<console>", line 1, in <module>
File "/Users/davidezanotti/CygoraPythonEnv/lib/python2.7/site-packages/celery/__init__.py", line 130, in <module>
from .five import recreate_module
File "/Users/davidezanotti/CygoraPythonEnv/lib/python2.7/site-packages/celery/five.py", line 51, in <module>
from kombu.five import monotonic
File "/Users/davidezanotti/CygoraPythonEnv/lib/python2.7/site-packages/kombu/five.py", line 47, in <module>
libSystem = ctypes.CDLL('libSystem.dylib')
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 365, in __init__
self._handle = _dlopen(self._name, mode)
OSError: dlopen(libSystem.dylib, 6): image not found
I'm using python 2.7.6 with VirtualEnv and macports on OS X 10.8.5
I understand that the problem is that an underlying dependency ("libSystem.dylib") is missing, but I don't know how to fix this issue
(under /usr/lib/ I can find libSystem.dylib on my machine)
Just add /usr/lib to DYLD_FALLBACK_LIBRARY_PATH will resolve this issue.
The problem was that I had defined a DYLD_FALLBACK_LIBRARY_PATH in my .bash_profile, by following literally the notes about macports in Django documentation on postgis: https://docs.djangoproject.com/en/1.6/ref/contrib/gis/install/#macports
but this leads to unexpected behavior like the one I faced, anyway by commenting it out, all seems to work!

Python 2.7.5 installation on Ubuntu, MAXREPEAT

This has been asked a couple of times but the answers do not make any sense at least to me. I have Ubuntu 12.04 and had to upgrade Python from default (2.7.3?) to 2.7.5 to get libraries I can use to compile modwsgi.
I obtained 2.7.5 sources, configured with --enable-shared, made and installed. A few obsolete sun audio etc libraries could not be built but otherwise the installation went through. Except that it doesn't work:
visti#ubuntu:~$ python
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site.py", line 548, in <module>
main()
File "/usr/local/lib/python2.7/site.py", line 530, in main
known_paths = addusersitepackages(known_paths)
File "/usr/local/lib/python2.7/site.py", line 266, in addusersitepackages
user_site = getusersitepackages()
File "/usr/local/lib/python2.7/site.py", line 241, in getusersitepackages
user_base = getuserbase() # this will also set USER_BASE
File "/usr/local/lib/python2.7/site.py", line 231, in getuserbase
USER_BASE = get_config_var('userbase')
File "/usr/local/lib/python2.7/sysconfig.py", line 516, in get_config_var
return get_config_vars().get(name)
File "/usr/local/lib/python2.7/sysconfig.py", line 449, in get_config_vars
import re
File "/usr/local/lib/python2.7/re.py", line 105, in <module>
import sre_compile
File "/usr/local/lib/python2.7/sre_compile.py", line 14, in <module>
import sre_parse
File "/usr/local/lib/python2.7/sre_parse.py", line 17, in <module>
from sre_constants import *
File "/usr/local/lib/python2.7/sre_constants.py", line 18, in <module>
from _sre import MAXREPEAT
ImportError: cannot import name MAXREPEAT
The suggested solution here ubuntu ImportError: cannot import name MAXREPEAT was to reconfigure "virtualenv", whatever it is. /usr/local/bin has an ancient script named virtualenv but it tries to run python as well and doesn't work.
Someone suggested the problem might be related to using old Python modules as MAXREPEAT appeared in 2.7.4. To counter this I removed everything related to Python with rm -rf (/usr/bin/python*, /usr/lib/python*, /usr/local/lib/python*, /usr/local/bin/python*, did make clean, make, make install to 2.7.5.
Still the same result. Now I don't have a working version of Python anymore. Is there any way to fix this or should I try reinstalling Ubuntu Python packages if they have 2.7.5 available?
Hannu
Just battled the same problem. Ended up deleting the entire /usr/local/lib/python2.7 install path just to get back to the previous working version.
Also be sure to remove /usr/local/lib/python2.7-config, then reinstall python. Worked for me anyway.
This usually happens when you mix and match libpython.so versions with python interpreter versions. If nuking your install paths didnt help, check these environment variables.
$PYTHONHOME $PYTHONINCLUDE $PYTHONLIB $PYTHONLIBSTATIC $PYTHONPATH
Make sure what they point to were all deleted as well. And then reinstall.
You can also try and install python to a home directory, by configuring the -prefix variable to point to a home dir.
make configure -prefix=$HOME/mypython`
Then make sure you set those above variables to the new home directory python resides in.
The way I fixed this was by searching my system for other instances of the sre_constants.py file. Then see if the location of those files is referenced in your user or system $PATH. If so, remove that location configuration from your $PATH. Rerun python to see if that fixed it.
In my case, it seemed that Python is referencing the wrong location which does not does not support MAXREPEAT.

Categories