2015-09-02 35 views
0

我正在構建一個需要mysql作爲後端的django項目。沒有在virtualenv中安裝MySQL-python(EnvironmentError:找不到mysql_config)

我創建了一個的virtualenv並嘗試使用PIP

pip install MySQL-python 
    Downloading/unpacking MySQL-python==1.2.5 
    Downloading MySQL-python-1.2.5.zip (108kB): 108kB downloaded 
    Running setup.py (path:/home/sayone/virtual/myvinotype/build/MySQL-python/setup.py) egg_info for package MySQL-python 
    sh: 1: mysql_config: not found 
........ 
EnvironmentError: mysql_config not found 

安裝MySQL-python的通過搜索我發現我需要安裝的libmysqlclient-dev的

sudo apt-get install libmysqlclient-dev 
Reading package lists... Done 
Building dependency tree  
Reading state information... Done 
Some packages could not be installed. This may mean that you have 
requested an impossible situation or if you are using the unstable 
distribution that some required packages have not yet been created 
or been moved out of Incoming. 
The following information may help to resolve the situation: 

The following packages have unmet dependencies: 
libmysqlclient-dev : Depends: libmysqlclient18 (= 5.5.44-0ubuntu0.14.04.1) but 10.0.21+maria-1~trusty is to be installed 
E: Unable to correct problems, you have held broken packages. 

要安裝MySQL-python我們需要安裝libmysqlclient-dev,但它最終在未滿足的依賴與mariadb(不確定)

Os:Ubuntu 14.04 LTS

任何幫助,非常感謝。

編輯:安裝sudo apt-get install libmariadbclient-dev之後我能夠安裝MySQL-python沒有任何問題(我不知道這是可以添加爲答案)。

+0

如果您使用的是Python 3.4版,我會建議您切換回2.7版。安裝mysql時,版本3.4中存在問題。 –

+1

@MuhammadShoaib [Django文檔](https://docs.djangoproject.com/en/1.8/ref/databases/#mysql-db-api-drivers)推薦使用'mysqlclient'而不是'MySQL-python'。它適用於Python 3.3+,所以不需要降級到2.7。 – Alasdair

+0

@MuhammadShoaib我使用Python 2.7 –

回答

0

運行apt-cache policy libmysqlclient18 &你會看到你有一個版本libmysqlclient18mariadb。如果他們沒有提供開發包,那麼你將需要沒有開發包或擺脫mariadb &無論它的安裝

+0

Ajay Gupta我沒有完全得到我應該做的,請在上面的評論中找到'apt-cache policy libmysqlclient18'的結果。但'sudo apt-get install libmariadbclient-dev'後,我可以毫無困難地安裝'MySQL-python'。 –