加载MySQLdb模块时出错和" pip install MySQLdb"

时间:2015-12-01 21:10:25

标签: python mysql django packages python-module

我正在尝试启动Django项目。

我在尝试运行manage.py时遇到此错误:

pip install MySQLdb

我想知道我应该尝试安装哪个模块。

当我使用 Collecting MySQLdb Could not find a version that satisfies the requirement MySQLdb (from versions: ) No matching distribution found for MySQLdb 时,我收到此错误:

    DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',

当我在SO和其他地方查看时,似乎有很多不同的mysql模块。

这也是我的设置看起来像DB(我没有写这个项目,我很大程度上是django和python):

    }
}

...

pip install MySQL-python

EdBaker建议Collecting MySQL-python Using cached MySQL-python-1.2.5.zip Complete output from command python setup.py egg_info: sh: mysql_config: command not found Traceback (most recent call last): File "<string>", line 20, in <module> File "/private/var/folders/m3/11zknyw55zxbw6zqh58rwq580000gn/T/pip-build-DC9tSL/MySQL-python/setup.py", line 17, in <module> metadata, options = get_config() File "setup_posix.py", line 43, in get_config libs = mysql_config("libs_r") File "setup_posix.py", line 25, in mysql_config raise EnvironmentError("%s not found" % (mysql_config.path,)) EnvironmentError: mysql_config not found ---------------------------------------- Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/m3/11zknyw55zxbw6zqh58rwq580000gn/T/pip-build-DC9tSL/MySQL-python

我得到了这个回复:

[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named MySQLdb

尝试在shell中运行导入MySQLdb:

pip install pip --upgrade

尝试升级pip:

Requirement already up-to-date: pip in /Users/Bren/Desktop/fss/venv/lib/python2.7/site-packages

显示pip是最新的

/* @flow weak */

3 个答案:

答案 0 :(得分:18)

显然,安装pip install MySQL-python是可行的方法。问题在于mysql_config的位置。在这里查看,这可能会对您有所帮助,具体取决于您的操作系统:mysql_config not found when installing mysqldb python interface

修改

如果安装脚本失败并显示Command "python setup.py egg_info" failed with error code 1 in {...},请使用

安装libmysqlclient-dev
sudo apt install libmysqlclient-dev

应该解决问题。感谢@ thirupathi-thangavel。

答案 1 :(得分:0)

我在这里跟踪了我的问题404 error when using brew to install mysql

然后当fodma1建议去了这里stackoverflow.com/a/33928783/2419215

现在它大部分都有效(有另一个错误,但那是另一个帖子)!

感谢EdBaker和fodma1!

答案 2 :(得分:0)

brew install mysql

安装完成后将显示路径,请在以下命令中使用:

sudo PATH = / usr / local / Cellar / mysql / bin /:$ PATH pip install mysql-python