django安裝mysql驅動

來源:互聯網
上載者:User

標籤:django   python3   mysqlclient   python setup.py egg_info   error code 1   

django目前支援三種mysql驅動來進行mysql的連結

  • MySQLdb is a native driver that has been developed and supported for overa decade by Andy Dustman.

  • mysqlclient is a fork of MySQLdb which notably supports Python 3 andcan be used as a drop-in replacement for MySQLdb. At the time of this writing,this is the recommended choice for using MySQL with Django.

  • MySQL Connector/Python is a pure Python driver from Oracle that does notrequire the MySQL client library or any Python modules outside the standardlibrary.


mysqldb 目前不支援python3+,推薦使用mysqlclient

嘗試了在pycharm上直接安裝mysqlclient,報以下錯誤:OSError: mysql_config not found


在git上查閱安裝步驟:

Prerequisites

You may need to install the Python and MySQL development headers and libraries like so:

sudo apt-get install python-dev libmysqlclient-dev # Debian / Ubuntu

sudo yum install python-devel mysql-devel # Red Hat / CentOS

On Windows, there are binary wheel you can install without MySQLConnector/C or MSVC.

Note on Python 3 : if you are using python3 then you need to install python3-dev using the following command :

sudo apt-get install python3-dev # debian / Ubuntu

sudo yum install python3-devel # Red Hat / CentOS

brew install mysql-connector-c # macOS (Homebrew)

Install from PyPI

pip install mysqlclient

因為我在mac上,使用的python3,故先執行命令:

brew install mysql-connector-c 


然後再執行:

pip3 install mysqlclient

報如下錯誤:

Command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-build-m9v70gan/mysqlclient/

奇怪的是,使用pip3命令後,最終調用的是python,而不是python3

django安裝mysql驅動

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.