作者:Bright Xu
这里用的服务器是Ubuntu18.04,CentOS服务器 请参考 CentOS 解决
pip
安装mysqlclient
报错的问题
Django开发项目时使用MySQL数据库,然而部署到Ubuntu服务器的时候会经常出错。
Django连接MySQL数据库需要依赖第三方库mysqlclient
,然而服务器通过pip3 install mysqlclient
命令安装第三方库mysqlclient
时会经常报错:
ERROR: Command errored out with exit status 1:command: /home/bright/web/venv/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-ffv9cnlj/mysqlclient/setup.py'"'"'; __file__='"'"'/tmp/pip-install-ffv9cnlj/mysqlclient/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-ffv9cnlj/mysqlclient/pip-egg-infocwd: /tmp/pip-install-ffv9cnlj/mysqlclient/Complete output (12 lines):/bin/sh: 1: mysql_config: not found/bin/sh: 1: mariadb_config: not found/bin/sh: 1: mysql_config: not foundTraceback (most recent call last):File "<string>", line 1, in <module>File "/tmp/pip-install-ffv9cnlj/mysqlclient/setup.py", line 16, in <module>metadata, options = get_config()File "/tmp/pip-install-ffv9cnlj/mysqlclient/setup_posix.py", line 61, in get_configlibs = mysql_config("libs")File "/tmp/pip-install-ffv9cnlj/mysqlclient/setup_posix.py", line 29, in mysql_configraise EnvironmentError("%s not found" % (_mysql_config_path,))OSError: mysql_config not found----------------------------------------ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
用apt
安装的 mysql 的 mysql_config 文件缺失了,或者说系统里没有mysql_config
文件,,,,
解决方案:
sudo apt install libmysqlclient-dev
然后再:
pip3 install mysqlclient
发现:
Building wheels for collected packages: mysqlclientBuilding wheel for mysqlclient (setup.py) ... doneCreated wheel for mysqlclient: filename=mysqlclient-1.4.6-cp37-cp37m-linux_x86_64.whl size=100352 sha256=07ec9df2d857581eee041a6ae7740149919a265d19776c7eb8dbce47b4108324Stored in directory: /home/bright/.cache/pip/wheels/42/b3/81/881eb2e7c762ba99ec0349eeb2b8b03760871295b5800d7a51Successfully built mysqlclientInstalling collected packages: mysqlclientSuccessfully installed mysqlclient-1.4.6
mysqlclient
安装成功。
这样即使服务器里没有安装MySQL
数据库,也不会报错。