2017-04-26 106 views
0
當我跑步時 python3 manage.py runserver

我得到這個消息:不能Django的/ python3安裝msqlclient [OSX 10.12.4]

django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'. 
Did you install mysqlclient or MySQL-python? 

因爲我使用python的mysql數據庫,我試着安裝與PIP3的mysql我得到另一個錯誤:

Collecting mysqlclient 
    Using cached mysqlclient-1.3.10.tar.gz 
    Complete output from command python setup.py egg_info: 
    Traceback (most recent call last): 
     File "<string>", line 1, in <module> 
     File "/private/var/folders/dd/vlr9cjt17_j4ccyzz89mld1w0000gn/T/pip-build-wt6g2_0e/mysqlclient/setup.py", line 17, in <module> 
     metadata, options = get_config() 
     File "/private/var/folders/dd/vlr9cjt17_j4ccyzz89mld1w0000gn/T/pip-build-wt6g2_0e/mysqlclient/setup_posix.py", line 54, in get_config 
     libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')] 
     File "/private/var/folders/dd/vlr9cjt17_j4ccyzz89mld1w0000gn/T/pip-build-wt6g2_0e/mysqlclient/setup_posix.py", line 54, in <listcomp> 
     libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')] 
     File "/private/var/folders/dd/vlr9cjt17_j4ccyzz89mld1w0000gn/T/pip-build-wt6g2_0e/mysqlclient/setup_posix.py", line 12, in dequote 
     if s[0] in "\"'" and s[0] == s[-1]: 
    IndexError: string index out of range 

     ---------------------------------------- 
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/dd/vlr9cjt17_j4ccyzz89mld1w0000gn/T/pip-build-wt6g2_0e/mysqlclient/ 

而且我在網上讀到的mysql不支持python3,但我得到試圖安裝裝配的MySQL蟒蛇當類似的錯誤:

Collecting MySQL-python 
    Using cached MySQL-python-1.2.5.zip 
    Complete output from command python setup.py egg_info: 
    Traceback (most recent call last): 
     File "<string>", line 1, in <module> 
     File "/private/var/folders/dd/vlr9cjt17_j4ccyzz89mld1w0000gn/T/pip-build-jp09s51k/MySQL-python/setup.py", line 13, in <module> 
     from setup_posix import get_config 
     File "/private/var/folders/dd/vlr9cjt17_j4ccyzz89mld1w0000gn/T/pip-build-jp09s51k/MySQL-python/setup_posix.py", line 2, in <module> 
     from ConfigParser import SafeConfigParser 
    ModuleNotFoundError: No module named 'ConfigParser' 

    ---------------------------------------- 
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/dd/vlr9cjt17_j4ccyzz89mld1w0000gn/T/pip-build-jp09s51k/MySQL-python/ 

我該如何解決這個問題併爲python安裝mysql客戶端,或者是否有其他方法,以便我可以在python中使用MySQL數據庫?

編輯:python3不支持mysqlclient,但不支持MySQL-python。

+0

您錯過了Python MySQL「驅動程序」。有一個關於如何在這裏安裝的答案:http://stackoverflow.com/a/25865271/190823 – Jens

+0

運行後:'brew安裝mysql-connector-c'我得到了msg,它已經安裝了「Warning:mysql-connector -c-6.1.9已經安裝「並運行pip安裝MySQL-python會拋出相同的錯誤。 – Mindutis

+0

*我在線閱讀mysqlclient不被python3支持,但在嘗試安裝MySQL-python *時遇到了類似的錯誤。你有錯誤的方式。 MySQL-python只支持Python 2.如果你使用Python 3,你需要mysqlclient。 – Alasdair

回答

0

我不知道我做了什麼,但我認爲我的問題是我有一個不好的$PATH。我正在嘗試執行我在Google上找到的其中一個步驟,並且在重新設置bash_profile並重新設置Python路徑後,它對我來說已經修復了。