2017-02-21 223 views
1

我試圖在Django上構建一個應用程序,我想使用MySQL作爲數據庫。在設置settings.py後,我嘗試遷移。然後我得到了明顯的錯誤,說MySQL沒有安裝。所以序安裝MySQL,我跑:MYSQL- python pip安裝錯誤

sudo -H pip install MySQL-python 

我得到以下錯誤:

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 1, in <module> 
     File "/private/tmp/pip-build-zAMhWo/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/tmp/pip-build-zAMhWo/MySQL-python/ 

我該如何解決這個問題?

+0

的可能的複製[MySQL的\ _config安裝MySQLdb的蟒接口時未找到(http://stackoverflow.com/questions/7475223/mysql-config-not-found-when -installing-mysqldb-python-interface) –

回答

4

的MySQL-python的

MySQL-3.23 through 5.5 and Python-2.4 through 2.7 are currently supported. Python-3.0 will be supported in a future release.

您可以安裝的mysql或pymysql,我更喜歡後者:

pip install pymysql 

並添加到您的manage.py

import pymysql 
pymysql.install_as_MySQLdb() 
+0

sudo和你的命令工作。但我仍然無法運行python manage.py migrate。 –

+1

@GeethW將此添加到您的'manage.py','import pymysql' 'pymysql.install_as_MySQLdb()' – McGrady

+0

非常感謝McGrady。我真的不明白髮生了什麼事。你可以解釋嗎?我嘗試了很多驅動選項。例如,pip安裝mysql-python,然後從oracle手動下載.dmg。沒有工作。請解釋。 –

0

我面對試圖安裝的mysql同樣的問題,嘗試安裝的mysql-devel的。在RHEL/Centos的例如:

yum install mysql-devel