Django无法找到MySQLdb python模块 [英] Django unable to find MySQLdb python module
问题描述
从源代码安装Django(python setup.py安装等),从源代码安装MySQLdb(python setup.py构建,python setup.py安装).使用操作系统(CentOS 5.5)上安装的Python 2.4.启动服务器后收到以下错误消息:
Installed Django from source (python setup.py install and such), installed MySQLdb from source (python setup.py build, python setup.py install). Using Python 2.4 which came installed on the OS (CentOS 5.5). Getting the following error message after launching the server:
Error loading MySQLdb module: No module named MySQLdb
调试信息提供的pythonpath包括
The pythonpath the debug info provides includes
'/usr/lib/python2.4/site-packages'
但是,如果我ls
该目录,我可以清楚地看到
and yet, if I ls
that directory, I can plainly see
MySQL_python-1.2.3-py2.4-linux-i686.egg
使用python交互式shell,我可以键入import MySQLdb
,并且不会产生任何错误.这使我相信这是Django的路径问题,但是由于我是Django和python的新手,所以我丝毫没有发现任何线索的地方.
Using the python interactive shell, I can type import MySQLdb
and it produces no errors. This leads me to believe it's a Django pathing issue, but I haven't the slightest clue where to start looking as I'm new to both Django and python.
更具体地说,当前所有内容都以root身份运行.我还没有在计算机上设置任何用户,因此除root之外没有其他用户.
And to be a bit more specific, everything is currently running as root. I haven't setup any users yet on the machine, so none exist other than root.
EDITx2:更具体地说,Web服务器是Cherokee,并使用uWSGI进行部署.全部从源安装.
EDITx2: And to be even more specific, web server is Cherokee, and deploying using uWSGI. All installed from source.
推荐答案
您是否考虑过从python软件包安装MySQLdb?
我还建议您使用pip
而不是easy_install
来完成此操作.
Have you considered installing MySQLdb from python packages?
I would also recommend doing this with pip
instead of easy_install
.
首先,您可以将easy_install
替换为pip
:
First you can replace easy_install
with pip
:
easy_install pip
pip install pip --upgrade
然后通过PIP安装Django:
And then install Django via PIP:
pip install MySQL-python
pip install Django
通常已经安装了easy_install
(是setuptools的一部分),而pip更好.它还提供了卸载选项,并使用固定安装目录而不是EGG文件魔术.这也可能会解决一些不兼容问题.
Typically easy_install
is installed already (part of setuptools), while pip is much better. It offers uninstallation options too, and uses flat install directories instead of the EGG files magic. This might resolve some incompatibilities as well.
这篇关于Django无法找到MySQLdb python模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!