Tried to import _mysql through MySQLdb and get the error - python

I'm trying to use MySQLdb and when I try to import it I get the following error. Any thoughts? I'm currently using an ubuntu instance on aws.
>>> import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/pymodules/python2.6/MySQLdb/__init__.py", line 19, in <module>
import _mysql
ImportError: libmysqlclient_r.so.16: cannot open shared object file: No such file or directory
>>>

Is libmysqlclient-dev installed? Package might not be exact, but thats the general idea.

Is this comment thread of any help?
Try updating /etc/ld.so.conf so as to include the directory in which you've installed this.

After struggling with this same issue myself (on the AWS Linux I AMI), I found the answer
here:
While the comment thread already posted was helpful, Apache was clearing my environment variables, so setting LD_RUN_PATH and/or LD_LIBRARY_PATH was not effective.
What ended up working was adding a new include statement to /etc/ld.so.conf and running ldconfig.

Related

codeanywhere.com Python doesn't see virtualenv

I use codeanywhere.com try to create application with Python werkzeug and jinja2.
I install those library utilize virtualenv. Now I face the problem
Traceback (most recent call last):
File "manage.py", line 4, in
from werkzeug import Request
ImportError: No module named 'werkzeug'
virtualenv activated but nothing is works.
Does anybody has experience with codeanywhere.com?
Oh I solve this problem. In the container config file add instruction "source venv3/bin/activate" as shown on a picture add path to python as well.
enter image description here

Configure python model in xampp

I installed mod_python, I try to run python script like:
from mod_python import apache
It show me the error message:
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
from mod_python import apache
File "D:\Python27\lib\mod_python\apache.py", line 55, in <module>
import _apache
ImportError: No module named _apache
I don't know why?
My enviroment:
Windows XP, Python 2.7.2
If you don't get any help here, try the mod_python mailing list:
http://www.modpython.org/live/mod_python-2.7.8/doc-html/installation.html
Its probably that the script location is not added to your path.
try:
import sys
sys.path
sys.path.append('/path/to/the/mod_python.py')
If this doesn't work, it was probably not installed correctly.
If you want to add it to your system path permanently so you don't have to use the code above every time check out this SO question.

python "ImportError: cannot import name urandom"

Somehow my python is broken and emits the error:
jseidel#EDP15:/etc/default$ python -c 'import random'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python2.6/random.py", line 47, in <module>
from os import urandom as _urandom
ImportError: cannot import name urandom
This is NOT the virtualenv error that is so commonly documented here and elsewhere: I don't use python directly, I have never setup a virtualenv explicitly, and there is no virtualenv directory or python script that I can find anywhere on my system.
I'm running Kubuntu 10.04 and until just recently my KPackageKit worked just fine and handled updates with no problem. Now it shows nothing... maybe because of this python error, maybe because of something else.
How do I go about finding the error and fixing python?
As suggested by #Armin Rigo, this worked for me:
1) Add a print 42 at the end of the /usr/lib/python2.6/os.py file.
2) If you see "42", then that is the correct os.py file and the urandom module is not include. Add the statement to include urandom (you can find a sample from another os.py file). This was what worked for me.
3) If you don't see "42", then that's not the os.py file that you're using. Find the random.py file that is crashing and insert import os; print os.__file__ to get more information about the failure.

Python/django : Cannot import GeoIP

I cannot import GeoIP in django. I searched and tested this error two days, but still could not know problem.
Surely, I installed GeoDjango. I'm on MacOS 10.8
following is log by tested by django shell
from django.contrib.gis import geoip
module 'django.contrib.gis.geoip' from '/Library/Python/2.7/site-packages/django/contrib/gis/geoip/__init__.pyc'
it works. even I could find geoip class at Library/Python/2.7/site-packages/django/contrib/gis/geoip/base.py
from django.contrib.gis.geoip import geoip
Traceback (most recent call last):
File "", line 1, in
ImportError: cannot import name geoip
I also add django.contrib.gis to setting.py. Even I could find geoip class at eclipse shortcut.
anyway, I tested one more thing in django shell.
from django.contrib.gis.geoip.base import GeoIP
Traceback (most recent call last):
File "", line 1, in
File "/Library/Python/2.7/site-packages/django/contrib/gis/geoip/base.py", line 6, in
from django.contrib.gis.geoip.libgeoip import GEOIP_SETTINGS
File "/Library/Python/2.7/site-packages/django/contrib/gis/geoip/libgeoip.py", line 22, in
if lib_path is None: raise GeoIPException('Could not find the GeoIP library (tried "%s"). '
NameError: name 'GeoIPException' is not defined
What I missing?
Is there any way to test my error?
It appears you need to install a C library in order to use GeoIP.
Here is a snippet from the file that is throwing that error.
# The shared library for the GeoIP C API. May be downloaded
# from http://www.maxmind.com/download/geoip/api/c/
if lib_path:
lib_name = None
else:
# TODO: Is this really the library name for Windows?
lib_name = 'GeoIP'
Once you have it installed somewhere you need to reference it in your settings.py
GEOIP_LIBRARY_PATH = '/whatever'
The library was trying to tell you this, but it seems that there is a bug that prevents it from raising the correct error. https://github.com/django/django/pull/103
Previously i was facing this issue : from django.contrib.gis.geoip import GeoIP ImportError: cannot import name GeoIP
which is solved when i install this package.
yum install GeoIP-devel -y
The error is caused by moving the virtual environment folder.
The solution is to create the environment again and reinstall the pygeoip library.

Why do I receive an ImportError when running one of the CherryPy tutorials

I have installed CherryPy 3.1.0,. Here is what happens when I try to run tutorial 9:
$ cd /Library/Python/2.5/site-packages/cherrypy/tutorial/
$ python tut09_files.py
Traceback (most recent call last):
File "tut09_files.py", line 48, in <module>
from cherrypy.lib import static
ImportError: cannot import name static
The previous line in the file:
import cherrypy
passes without error, so it appears that it can find cherrypy on the path. What am I missing?
This works for me, and I'm also using CherryPy 3.1.0, so I'm not sure what to tell you.
Look in your /Library/Python/2.5/site-packages/cherrypy/lib directory for a file named static.py; if this file exists then I'm not sure what to tell you. If it doesn't then something has happened to your CherryPy and I'd advise you to reinstall. If it does then you should check the value of sys.path to make sure it's detecting the right version of CherryPy.
You can also try running the python interpreter on the command line and then doing a from cherrypy.lib import static to see if you get the same result.
I had an old CherryPy-2.3.0-py2.5.egg file in my site-packages. After removing the old .egg I could run the tutorial.

Categories

Resources