django裏mysql backend用的mysqlclient,因此使用的話須要安裝,但安裝比較坑比php
覺得就是一條命令的事python
pip install mysqlclient
但連續不斷的錯誤坑了有近2個小時mysql
1. 首先遇到的是git
EnvironmentError: mysql_config not foundgithub
網上查了下,大體意思是說須要安裝mysql,不能把,就連一下數據庫,還須要下一個數據庫?又繼續看了下,原來是要裝一個mysql的開發包就能夠了(固然你安裝mysql也是能夠的)sql
2. 因而 數據庫
brew install mysql-connector-cdjango
3. 再次 pip install mysqlclientbash
$ pip install mysqlclient Collecting mysqlclient Using cached mysqlclient-1.3.12.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/y5/rz5w2dqx00s24rgcgdzyf9z80000gn/T/pip-build-jckrqk4x/mysqlclient/setup.py", line 17, in <module> metadata, options = get_config() File "/private/var/folders/y5/rz5w2dqx00s24rgcgdzyf9z80000gn/T/pip-build-jckrqk4x/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/y5/rz5w2dqx00s24rgcgdzyf9z80000gn/T/pip-build-jckrqk4x/mysqlclient/setup_posix.py", line 54, in <listcomp> libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')] File "/private/var/folders/y5/rz5w2dqx00s24rgcgdzyf9z80000gn/T/pip-build-jckrqk4x/mysqlclient/setup_posix.py", line 12, in dequote if s[0] in "\"'" and s[0] == s[-1]: IndexError: string index out of range
仍是報錯,不至於這麼複雜吧ui
因而到mysqlclient源碼github目錄看了下,原來人家早就註明了😳(因此出現問題第一找官網)
以下:
You may need to install the Python and MySQL development headers and libraries like so:
sudo apt-get install python-dev libmysqlclient-dev
# Debian / Ubuntusudo yum install python-devel mysql-devel
# Red Hat / CentOSbrew install mysql-connector-c
# macOS (Homebrew) (Currently, it has bug. See below)On Windows, there are binary wheels you can install without MySQLConnector/C or MSVC.
sudo apt-get install python3-dev
# debian / Ubuntu
sudo yum install python3-devel
# Red Hat / CentOS
See also: https://bugs.mysql.com/bug.php?id=86971
Versions of MySQL Connector/C may have incorrect default configuration options that cause compilation errors when mysqlclient-python
is installed. (As of November 2017, this is known to be true for homebrew's mysql-connector-c
and official package)
Modification of mysql_config
resolves these issues as follows.
Change
# on macOS, on or about line 112: # Create options libs="-L$pkglibdir" libs="$libs -l "
to
# Create options libs="-L$pkglibdir" libs="$libs -lmysqlclient -lssl -lcrypto"
修改mysql_config時由於是隻讀的,須要chmod 777 設置下,改完後再改回來
修改完後 再次安裝ok了