web.py 不导入 MySQLdb
我正在使用 web.py,由于某种原因,我收到以下错误:
[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
这是我的 sys.path,以防万一这是罪魁祸首?不过我看到了蛋,所以我不知道。想法?
['', '/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']
以下是 2.6 site-packages 目录的内容:
[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
如果我打开 python(2.4 或 2.6),我可以毫无问题地导入 MySQLdb
。
谢谢, 汤姆
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 bashrc 文件的底部(通常在
/etc/bashrc
中)放置此文件(或者只更新PYTHONPATH
环境变量以包含/usr/lib/python2 .6/site-packages
):或者,对于运行脚本的特定用户,将上述内容放入
/home/[USER_RUNNING_SCRIPT]/.bashrc
中。然后获取文件:
At the bottom of your bashrc (usually in
/etc/bashrc
) file put this (or just update thePYTHONPATH
env variable to include/usr/lib/python2.6/site-packages
):Or, for the specific user that is running the script, put the above in
/home/[USER_RUNNING_SCRIPT]/.bashrc
.Then source the file:
您可以在以下位置下载 mysqldb: http://sourceforge.net/projects/mysql-python/
You can download mysqldb at : http://sourceforge.net/projects/mysql-python/
尝试编写一个简单的页面来显示 sys.path,因为它存在于 Web 服务器执行环境中。不确定这是否是您在问题中显示 sys.path 时所显示的内容,或者是否通过登录交互式运行该路径。运行 http 服务器的用户 ID 的环境设置可能与普通用户的环境不同。
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.