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.
Related
I had this project running on my Mac here under python3. It took a while after doing a 2to3 to update some other bits and pieces to it to finally get it to run. Now though the project fails and all I recall of doing to my mac is:
Upgrading the OS
Upgrading Xcode and other pieces so that a 'brew install root' would work.
Not sure what else it touched but it is like it lost all the modules I had done a pip install on. So i redid a pip install on several modules
astropy
matplotlib
scipy
now the project fails when I run it:
File "/Users/shathoma/TUI3/TUI/Guide/GuideImage.py", line 26, in <module>
import astropy.io.fits as pyfits
File "/usr/local/lib/python3.9/site-packages/astropy/io/fits/__init__.py", line 70, in <module>
from . import convenience
File "/usr/local/lib/python3.9/site-packages/astropy/io/fits/convenience.py", line 63, in <module>
from .diff import FITSDiff, HDUDiff
File "/usr/local/lib/python3.9/site-packages/astropy/io/fits/diff.py", line 25, in <module>
from .header import Header
File "/usr/local/lib/python3.9/site-packages/astropy/io/fits/header.py", line 11, in <module>
from .file import _File
File "/usr/local/lib/python3.9/site-packages/astropy/io/fits/file.py", line 29, in <module>
from astropy.utils.compat.optional_deps import HAS_BZ2
File "/usr/local/lib/python3.9/site-packages/astropy/utils/compat/__init__.py", line 19, in <module>
from .numpycompat import * # noqa
File "/usr/local/lib/python3.9/site-packages/astropy/utils/compat/numpycompat.py", line 14, in <module>
NUMPY_LT_1_19 = not minversion('numpy', '1.19')
File "/usr/local/lib/python3.9/site-packages/astropy/utils/decorators.py", line 546, in wrapper
return function(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/astropy/utils/introspection.py", line 167, in minversion
return Version(module_version) >= Version(version)
File "/usr/local/lib/python3.9/site-packages/packaging/version.py", line 264, in __init__
match = self._regex.search(version)
TypeError: expected string or bytes-like object
I have this project running fine still under a windows machine and the versions of the installed modules like astropy etc are the same. Still fails on the mac with the above error. I could go in and fix packaging/version.py to deal with a self._regex.search(str(version)) which is a bad Idea I know (I tried that and since reverted it gave an error on how version = none somewhere.
it is almost like I am missing a module but nothing knows it? Not sure, and not sure how after working this broke with just probably the brew install command of the root (https://root.cern.ch/) package. Out of ideas what to look for or try next to get this running again?
When I try the "python" or "python3" command to run the interpreter, this is the error am getting.
[sidgupta234#sidgupta234-Lenovo-G580 Downloads]$ python
Failed to import the site module
Traceback (most recent call last):
File "/usr/lib/python3.5/site.py", line 580, in <module>
main()
File "/usr/lib/python3.5/site.py", line 566, in main
known_paths = addusersitepackages(known_paths)
File "/usr/lib/python3.5/site.py", line 287, in addusersitepackages
user_site = getusersitepackages()
File "/usr/lib/python3.5/site.py", line 263, in getusersitepackages
user_base = getuserbase() # this will also set USER_BASE
File "/usr/lib/python3.5/site.py", line 253, in getuserbase
USER_BASE = get_config_var('userbase')
File "/usr/lib/python3.5/sysconfig.py", line 595, in get_config_var
return get_config_vars().get(name)
File "/usr/lib/python3.5/sysconfig.py", line 538, in get_config_vars
_init_posix(_CONFIG_VARS)
File "/usr/lib/python3.5/sysconfig.py", line 410, in _init_posix
from _sysconfigdata import build_time_vars
File "/usr/lib/python3.5/_sysconfigdata.py", line 6, in <module>
from _sysconfigdata_m import *
ImportError: No module named '_sysconfigdata_m'
Output to which python
[sidgupta234#sidgupta234-Lenovo-G580 Downloads]$ which python
/usr/bin/python
Output to python -V
[sidgupta234#sidgupta234-Lenovo-G580 Downloads]$ python -V
Python 3.5.2 :: Continuum Analytics, Inc.
Could you tell me the reason of this error and how can I remove it?
I found this link while looking for the solution, but it didnt make any difference.
I guess configuring_apache_django_anaconda is relevant, if you look at the troubleshooting section.
This means that apache is using Python 2 instead of Python 3 to run a program that is designed for Python 3 only, and fails because Python 2 does not have the _sysconfigdata_m module. The solution is to add the following file to your apache envvar file (/etc/apache2/envvar):
export PATH=/opt/anaconda3/bin:$PATH
So maybe check which version of python anaconda is running?
Also these two might be related:Linux - Weird Python Output
ubuntu anaconda suggested fix
I would suggest you print your PATH variable to see if you have several python3 entries in there, and try to specify explicity which one to run.
That is an strange situation you have gotten yourself into, and if Continuum had any part of it (where I'm an engineer) we'd like to understand what we did that led to it so we can avoid it in the future.
Where did you try installing Anaconda? Did you set any environment variables?
The "easiest-to-resolve" cause of this problem is that you have set some environment variables that are mixing system Python libraries and Anaconda Python libraries. You should look at the output of:
env | grep -i anaconda
and see if anything comes up that specifies a path to Anaconda. The only one that should appear is an entry in PATH. If there are any LD_LIBRARY_PATH, PYTHONPATH, PYTHONHOME or similar environment variables that point to Anaconda then that is going to be a problem.
The only other thing I can think of is that you specified /usr as the install path for Anaconda. If that is the case you are probably in for a world of pain: you have just replaced your system Python with Anaconda. You should investigate how to force-reinstall whichever Python package comes with your *nix distribution, but even that might be tricky: tools such as yum are written in Python and will need a working system Python interpreter to work. But RPM is binary (if you're on a RedHat or derivative distro), so maybe you can wget or curl the necessary system Python packages and force-install them to try and fix things.
Let us know if that is enough information for you to fix things or at least identify the source of the problem a little better.
I will first state I have searched for this problem, and found the exact same problem here ( ImportError: No module named 'requests' ) but that hasn't helped me.
I am using macports on osx (mountain lion). I have successfully installed and run a few scripts without any issues.
from the macports page, I have installed requests via the method it detailed and as far as I can tell, it has installed successfully:
daves-mbp:~ Dave$ port search requests
arpwatch #2.1a15 (net)
Monitor ARP & RARP requests
http_ping #29jun2005 (net, www)
Sends HTTP requests every few seconds and times how long they take
httping #2.0 (net, www)
Ping-like tool for http-requests
py-requests #1.2.3 (python, devel)
Python HTTP for Humans.
py26-requests #1.2.3 (python, devel)
Python HTTP for Humans.
py27-requests #1.2.3 (python, devel)
Python HTTP for Humans.
py31-requests #1.2.3 (python, devel)
Python HTTP for Humans.
py32-requests #1.2.3 (python, devel)
Python HTTP for Humans.
py33-requests #1.2.3 (python, devel)
Python HTTP for Humans.
webredirect #0.3 (www)
small webserver which redirects all requests
Found 10 ports.
I have python 2.7, so I installed it via:
daves-mbp:~ Dave$ sudo port install py27-requests
Password:
---> Computing dependencies for py27-requests
---> Fetching archive for py27-requests
---> Attempting to fetch py27-requests-1.2.3_0.darwin_12.noarch.tbz2 from http://jog.id.packages.macports.org/macports/packages/py27-requests
---> Attempting to fetch py27-requests-1.2.3_0.darwin_12.noarch.tbz2.rmd160 from http://jog.id.packages.macports.org/macports/packages/py27-requests
---> Installing py27-requests #1.2.3_0
---> Activating py27-requests #1.2.3_0
---> Cleaning py27-requests
---> Updating database of binaries: 100.0%
---> Scanning binaries for linking errors: 100.0%
---> No broken files found.
daves-mbp:~ Dave$
I think that looks good. Using macports is there something else I have to do before using it? I thought the python setup.py install (in the aforementioned post) may have solved my problem, however, when I search for requests in my filesystem, the only reference is burried in a path (that macports says is a store for user installed modules. And besides, there is no setup.py within that or it's parent directory.
I have restarted my terminal window (that fixed another problem earlier), but it made no difference here.
Any help is appreciated
edit:
which python reports /opt/local/bin/python
the first lines of the python interpreter DID report:
daves-mbp:~ Dave$ python
Python 2.7.2 (default, Jun 20 2012, 16:23:33)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
but now I have done something and it's responding with new errors:
daves-mbp:~ Dave$ python
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 548, in <module>
main()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 530, in main
known_paths = addusersitepackages(known_paths)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 266, in addusersitepackages
user_site = getusersitepackages()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 241, in getusersitepackages
user_base = getuserbase() # this will also set USER_BASE
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 231, in getuserbase
USER_BASE = get_config_var('userbase')
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sysconfig.py", line 516, in get_config_var
return get_config_vars().get(name)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sysconfig.py", line 449, in get_config_vars
import re
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py", line 105, in <module>
import sre_compile
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sre_compile.py", line 14, in <module>
import sre_parse
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sre_parse.py", line 17, in <module>
from sre_constants import *
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sre_constants.py", line 18, in <module>
from _sre import MAXREPEAT
ImportError: cannot import name MAXREPEAT
In trying to sort this out, I have broken python, and eventually I got it going again.
I think initially I had not run one of the port select --set... commands. Once I realised this might be the case, I did so, but that produced the errors at the top. MAXREPEATS, a circular reference perhaps? No idea.
I have read here (macports didn't place python_select in /opt/local/bin) and here (How do I uninstall python from OSX Leopard so that I can use the MacPorts version?) about the --set command not working and to try sudo port select python python26 (i used python27) instead.
I checked the PATH and python didn't appear, so I updated that as well.
I got my python interpreter back and low-and-behold imports requests now works.
I think at the end of it all, there were two errors:
I used --set instead of the newer command, and
my path wasn't set
edit: Actually, after more debugging, I found the error was on the first line of my script, I had defined which python to use (which was the default apple one, which doesn't include the module). Once I updated the shebang line, it worked.
I have a python application primarily dependent on matplotlib, tkinter, numpy and scipy I have been distributing for multiple operating systems. I build these on top of the python.org version of python 2.6. For mac, I have had good success in the past with py2app and pyinstaller to build standalone versions of my application. Recently, however, I have included functions that require patsy, pandas and igraph and have had to move to the mac distributed version of python 2.6 in order to get igraph to work. All works fine in building a py2app version of my software on the Mac for my OS (10.6) but when I run on 10.8 I encountered the following error:
Traceback (most recent call last):
File "UI.pyc", line 603 createHeatMap
File "clustering.pyc", line 31, in <module>
File "mpl_toolkits/__init__.pyc", line 2, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 698, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 701, in Environment
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 96, in get_supported_platform
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 222, in get_build_platform
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/util.py", line 98, in get_platform
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/sysconfig.py", line 537, in get_config_vars
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/sysconfig.py", line 405, in _init_posix
DistutilsPlatformError: invalid Python installation: unable to open /user/include/python2.6/pyconfig.h (No such file or directory)
This is fixed by saving the file pyconfig.h to the designated location on the destination machine (not present in 10.8 but present in 10.6), which allows my application to work fine. In my py2app pacakge directory, under "Contents/Resources" there is a sym-link to the directory "include" which points to: /System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/pyconfig.h. If I include the pyconfig.h file as an addition resource in my py2app setup file, it also includes it in the package, but it still is not recognized.
Can anyone suggest a good work around for this that doesn't require me to use the python.org version of python (I've had horrible luck getting igraph to work with this).
Thanks...
This is a known issue in py2app, see https://bitbucket.org/ronaldoussoren/py2app/issue/36/py2app-fails-to-build-a-working-executable. The pyconfig.h file is only present on machines where the developer tools are installed, which is why I haven't noticed the problem myself.
The easiest workaround is probably to replace the pyconfig.h symlink by a copy of the file after creating the app bundle.
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