可先安装组件尝试
CentOS:
yum install libmysqld-dev libmysqlclient-dev
Ubuntu:
apt-get install libmysqld-dev libmysqlclient-dev
安装mysqlclient出错
参照:mysqlclient
本地环境:
Python-3.6.2
mysqlclient-1.3.7
mysql-connector-c-6.1.11
安装出错原因:
OSError: mysql_config not found
----------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/jf/qymg1tp13sb434xzh5knyl6r0000gn/T/pip-build-NlZGvS/mysqlclient/
解决办法之一:
首先需要安装 mysql-connector-c
命令:
brew install mysql-connector-c
然后错误会变成另外一个错误:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/2f/r1pwfcp521q7z9kd240tr3700000gn/T/pip-build-u8yhUI/mysqlclient/setup.py", line 17, in <module>
metadata, options = get_config()
File "setup_posix.py", line 54, in get_config
libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
File "setup_posix.py", line 12, in dequote
if s[0] in "\"'" and s[0] == s[-1]:
IndexError: string index out of range
这样,依据在issue中的方法,需要修改mysql_config文件的配置。位于/usr/local/bin/mysql_config
。
如下:
# origin code
# Create options
libs="-L$pkglibdir"
libs="$libs -l "
# change to
# Create options
libs="-L$pkglibdir"
libs="$libs -lmysqlclient -lssl -lcrypto"
此时重新安装pip3 install mysqlclient
.
成功了。
------- 重装系统后,上述方式失败了。。。
运行如下命令安装:
pip install -r requirements.txt --global-option=build_ext --global-option="-I/usr/local/opt/openssl/include" --global-option="-L/usr/local/opt/openssl/lib"