前置环境:python2.7,pip2,ubuntu22.04
1.先安装了mysql-server,再装mysql-python:
ERROR: Command errored out with exit status 1: command: /usr/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-kEMJ94/mysql-python/setup.py'"'"'; __file__='"'"'/tmp/pip-install-kEMJ94/mysql-python/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-pip-egg-info-GEgq5z cwd: /tmp/pip-install-kEMJ94/mysql-python/ Complete output (10 lines): sh: 1: mysql_config: not found Traceback (most recent call last): File "<string>", line 1, in <module> File "/tmp/pip-install-kEMJ94/mysql-python/setup.py", line 17, in <module> metadata, options = get_config() File "setup_posix.py", line 43, in get_config libs = mysql_config("libs_r") File "setup_posix.py", line 25, in mysql_config raise EnvironmentError("%s not found" % (mysql_config.path,)) EnvironmentError: mysql_config not found ---------------------------------------- ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
2.装环境:
apt install libmysqld-dev
apt install mysql-client
apt install libmysqlclient-dev
_mysql.c:29:10: fatal error: Python.h: No such file or directory 29 | #include "Python.h" | ^~~~~~~~~~ compilation terminated. error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
3.提示缺失Python.h
apt install python2-dev,安装对应python版本的python-dev即可
_mysql.c:44:10: fatal error: my_config.h: No such file or directory 44 | #include "my_config.h" | ^~~~~~~~~~~~~ compilation terminated. error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
4.提示缺失my_config.h,进入/usr/include/mysql/,下载一个my_config.h文件
wget https://raw.githubusercontent.com/paulfitz/mysql-connector-c/master/include/my_config.h
Installing collected packages: mysql-python Successfully installed mysql-python-1.2.5
🆗,安装成功!