为Django安装MySQL-python

Lio*_*cer 13 django virtualenv mysql-python

我刚刚学会了如何使用virtualenv并安装了Django 1.4.5.我假设virtualenv创建了一个干净的平板供我使用,安装了Django 1.4.5,我将以前的所有文件复制到virtualenv环境中.

我试图运行服务器,但我得到一个错误说"no module named MySQLdb".我想这意味着我忘了安装MySQL-python.我尝试通过它安装它

    pip install MySQL-python
Run Code Online (Sandbox Code Playgroud)

但是我得到了这个错误

    Downloading/unpacking MySQL-python
    Running setup.py egg_info for package MySQL-python
    The required version of distribute (>=0.6.28) is not available,
    and can't be installed while this script is running. Please
    install a more recent version first, using
    'easy_install -U distribute'.

    (Currently using distribute 0.6.24     (/home/bradford/Development/Django/django_1.4.5/lib/python2.7/site-packages/distribute-0.6.24-py2.7.egg))
    Complete output from command python setup.py egg_info:
    The required version of distribute (>=0.6.28) is not available,

    and can't be installed while this script is running. Please

    install a more recent version first, using

    'easy_install -U distribute'.



    (Currently using distribute 0.6.24  (/home/bradford/Development/Django/django_1.4.5/lib/python2.7/site-packages/distribute-0.6.24-py2.7.egg))

    ----------------------------------------
    Command python setup.py egg_info failed with error code 2 in /home/bradford/Development/Django/django_1.4.5/build/MySQL-python
Run Code Online (Sandbox Code Playgroud)

不太确定如何解决这个问题= /任何帮助非常感谢!

dav*_*one 23

我最近遇到了这个问题(与Django无关).在我的情况下,我使用默认的点子和分发版本在Ubuntu 12.04上进行开发,这些版本基本上已经过时了MySQL-python.

因为您正在使用隔离的virtualenv,所以可以安全地遵循建议的指令,而不会影响Python的安装.

所以你可以...

workon your_virtualenv #activate your virtualenv, you do use virtualenvwrapper, right?
easy_install -U distribute #update distribute on your virtualenv
pip install MySQL-python #install your package
Run Code Online (Sandbox Code Playgroud)

如果由于某种原因升级分发不是一个选项,您可以尝试安装旧版本,MySQL-python如下所示(您必须检查此版本是否与您的Django版本兼容):

pip install MySQL-python==x.y.z #where x.y.z is the version you want
Run Code Online (Sandbox Code Playgroud)


Art*_*sov 14

花了一个小时翻阅stackoverflow.在另一个问题中逐渐找到答案.这就是救我的:

sudo apt-get install libmysqlclient-dev
Run Code Online (Sandbox Code Playgroud)

mysql_config与包一起使用.


Pie*_*aux 8

在做virtualenv时:

pip install MySQL-python
Run Code Online (Sandbox Code Playgroud)

我有

EnvironmentError: mysql_config not found
Run Code Online (Sandbox Code Playgroud)

要安装mysql_config,正如Artem Fedosov所说,首先安装

sudo apt-get install libmysqlclient-dev
Run Code Online (Sandbox Code Playgroud)

然后在virtualenv中一切正常