문제

I'm working with web.py and for some reason I am getting the following error:

[Thu Sep 29 13:47:20 2011] [error] [client 64.8.210.120]   File "/usr/lib/python2.6/site-packages/web.py-0.36-py2.6.egg/web/db.py", line 975, in __init__
[Thu Sep 29 13:47:20 2011] [error] [client 64.8.210.120]     import MySQLdb as db
[Thu Sep 29 13:47:20 2011] [error] [client 64.8.210.120] ImportError: No module named MySQLdb

Here is my sys.path, in case that's the culprit? I see the.egg, though, so I don't know. Thoughts?

 ['', '/usr/lib/python2.6/site-packages/Bravo-1.7.2-py2.6.egg', 
    '/usr/lib/python2.6/site-packages/Twisted-11.0.0-py2.6-linux-i686.egg',
     '/usr/lib/python2.6/site-packages/construct-2.04-py2.6.egg',
 '/usr/lib/python2.6/site-packages/zope.interface-3.7.0-py2.6-linux-i686.egg', '/usr/lib/python2.6/site-packages/web.py-0.36-py2.6.egg', 
'/usr/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-linux-i686.egg', 
    '/usr/lib/python2.6/site-packages/setuptools-0.6c12dev_r88846-py2.6.egg',
     '/usr/lib/python26.zip', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', 
    '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/usr/lib/python2.6/site-packages',
     '/usr/lib/python2.6/site-packages/PIL']

Here are the contents of the 2.6 site-packages directory:

[root@xxxx ~]# locate *.egg
/root/MySQL-python-1.2.3/dist/MySQL_python-1.2.3-py2.6-linux-i686.egg
/usr/lib/python2.4/site-packages/errorhandler-1.1.1-py2.4.egg
/usr/lib/python2.4/site-packages/setuptools-0.6c11-py2.4.egg
/usr/lib/python2.4/site-packages/xlrd-0.7.1-py2.4.egg
/usr/lib/python2.4/site-packages/xlutils-1.4.1-py2.4.egg
/usr/lib/python2.4/site-packages/xlutils-1.4.1-py2.5.egg
/usr/lib/python2.4/site-packages/xlwt-0.7.2-py2.4.egg
/usr/lib/python2.6/site-packages/Bravo-1.7.2-py2.6.egg
/usr/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-linux-i686.egg
/usr/lib/python2.6/site-packages/Twisted-11.0.0-py2.6-linux-i686.egg
/usr/lib/python2.6/site-packages/construct-2.04-py2.6.egg
/usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg
/usr/lib/python2.6/site-packages/setuptools-0.6c12dev_r88846-py2.6.egg
/usr/lib/python2.6/site-packages/web.py-0.36-py2.6.egg
/usr/lib/python2.6/site-packages/zope.interface-3.7.0-py2.6-linux-i686.egg

If I open python (either 2.4 or 2.6), I am able to import MySQLdb with no problem.

Thanks, Tom

도움이 되었습니까?

해결책

At the bottom of your bashrc (usually in /etc/bashrc) file put this (or just update the PYTHONPATH env variable to include /usr/lib/python2.6/site-packages):

if [ $PYTHONPATH ]
then
    export PYTHONPATH=$PYTHONPATH:/usr/lib/python2.6/:/usr/lib/python2.6/site-packages/
else
    export PYTHONPATH=/usr/lib/python2.6/:/usr/lib/python2.6/site-packages/
fi

Or, for the specific user that is running the script, put the above in /home/[USER_RUNNING_SCRIPT]/.bashrc.

Then source the file:

$ source ~/.bashrc
# or
# source /etc/bashrc

다른 팁

You can download mysqldb at : http://sourceforge.net/projects/mysql-python/

Try writing a simple page to show the sys.path as it exists from within the web server execution environment. Not sure if that's what you're showing when you show your sys.path in your question or if you ran that interactively from your login. Chances are the userid that the http server is running under has a different environment set up from what you have as a regular user.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top