我在ubuntu20上安装了mysqlclient,遇到了很多错误。原因是mysqlclient需要依赖一些动态链接库,和python版本有关。环境介绍:ubuntu20自带python3.8,但是我自己安装了python3.9使用命令:sudoaptinstallpython3.9安装python3.9字幕:安装Pythonmysqlclient时出现“OSError:mysql_confignotfound”错误跨系统python版本安装python3.9-devforubuntu20安装python3.9-devubuntu自带我的python是3.8的。如何为3.9安装mysqlclient?c'导入io、os、sys、setuptools、tokenize;sys.argv[0]='"'"'/tmp/pip-install-ad2qu_uy/mysqlclient_df40fd48e0dc469e8a102567b171b787/setup.py'"'"';__file__='"'"'/tmp/pip-install-ad2qu_uy/mysqlclient_df40fd48e0dc469e8a102567b171b787/setup.py'"'"';f=getattr(tokenize,'"'"'open'"'"',open)(__file__)如果os.path。exists(__file__)elseio.StringIO('"'"'fromsetuptoolsimportsetup;setup()'"'"');code=f.read().replace('"'"'\r\n'"'"','"'"'\n'"'"');f.close();exec(编译(代码,__file__,'"'"'exec'"'"'))'egg_info--egg-base/tmp/pip-pip-egg-info-ksb3c8ihcwd:/tmp/pip-install-ad2qu_uy/mysqlclient_df40fd48e0dc469e8a102567b171b787/完成输出(15行):/bin/sh:1:mysql_config:notfound/bin/sh:1:mariadb_config:notfound/bin/sh:1:mysql_config:notfoundTraceback(最近调用最后):File"”,第1行,在文件“/tmp/pip-install-ad2qu_uy/mysqlclient_df40fd48e0dc469e8a102567b171b787/setup.py”中,第15行,在元数据中,选项=get_config()文件“/tmp/pip-install-ad2qu_uy/mysqlclient_df40fd48e0dc469e8a102567b171b787/setup_posix.py",line70,inget_configlibs=mysql_config("libs")File"/tmp/pip-install-ad2qu_uy/mysqlclient_df40fd48e0dc469e8a102567b171b787/setup_posix.py",line31,inmysql_configraiseOSError("{}notfound".format(_mysql_config_path))OSError:mysql_confignotfoundmysql_config--versionmariadb_config--versionmysql_config--libs----------------------------------------WARNING:Discardinghttps://pypi.tuna.tsinghua.edu.cn/packages/3c/df/59cd2fa5e48d0804d213bdcb1acb4d08c403b61c7ff7ed4dd4a6a2deb3f7/mysqlclient-2.0.3.tar.gz#sha256=f6ebea7c008f155baeefe16c56cd3ee6239f7a5a9ae42396c2f1860f08a7c432(fromhttps://pypi.tuna.tsinghua.edu.cn/simple/mysqlclient/)(requires-python:>=3.5).命令出错,退出状态为1:pythonsetup.pyegg_info检查日志以获取完整的命令输出。错误:找不到满足mysqlclient==2.0.3要求的版本(来自版本:1.3.0、1.3.1、1.3.2、1.3.3、1.3.4、1.3.5、1.3.6、1.3.7、1.3.8、1.3.9、1.3.10、1.3.11rc1、1.3.11、1.3.12、1.3。13、1.3.14、1.4.0rc1、1.4.0rc2、1.4.0rc3、1.4.0、1.4.1、1.4.2、1.4.2.post1、1.4.3、1.4.4、1.4.5、1.4。6,2.0.0,2.0.1,2.0.2,2.0.3)ERROR:Nomatchingdistributionfoundformysqlclient==2.0.3解决方法:sudoaptinstalllibmysqlclient-devpython3-dev如果你使用的python解释器版本与系统自带的python版本一致,那就没有问题。如果你使用的不是系统自带的python解释器(版本相同没有问题),继续阅读error2:ERROR:Commanderroredoutwithexitstatus1:command:/home/bot/。local/share/virtualenvs/django-twitter-IaucORjf/bin/python-u-c'importio,os,sys,setuptools,tokenize;sys.argv[0]='"'"'/tmp/pip-install-rq7aoqrc/mysqlclient_40fa5be227e344b0a851378f6a96cc9a/setup.py'"'"';__file__='"'"'/tmp/pip-install-rq7aoqrc/mysqlclient_40fa5be227e344b0a851378f6a96cc9a/setup.py'"'"';f=getattr(tokenize,'"'"'open'"'"',open)(__file__)ifos.path.exists(__file__)elseio.StringIO('"'"'fromsetuptoolsimportsetup;setup()'"'"');code=f.read()。replace('"'"'\r\n'"'"','"'"'\n'"'"');f.close();exec(compile(code,__file__,'"'"'exec'"'"'))'install--record/tmp/pip-record-n8yzv7f4/install-record.txt--single-version-externally-managed--compile--install-headers/home/bot/。本地/共享/virtualenvs/django-twitter-IaucORjf/include/site/python3.9/mysqlclientcwd:/tmp/pip-install-rq7aoqrc/mysqlclient_40fa5be227e344b0a851378f6a96cc9a/完整输出(46行):mysql_config--version['8.0.26']mysql_config--libs['-L/usr/lib/x86_64-linux-gnu'、'-lmysqlclient'、'-lpthread'、'-ldl'、'-lz'、'-lssl'、'-lcrypto'、'-lresolv'、'-lm'、'-lrt']mysql_config--cflags['-I/usr/include/mysql']ext_options:library_dirs:['/usr/lib/x86_64-linux-gnu']libraries:['mysqlclient','pthread','dl','resolv','m','rt']extra_compile_args:['-std=c99']extra_link_args:[]include_dirs:['/usr/include/mysql']extra_objects:[]define_macros:[('version_info',"(2,0,3,'final',0)"),('__version__','2.0.3')]runninginstallrunningbuildrunningbuild_pycreatingbuildcreatingbuild/lib.linux-x86_64-3.9creatingbuild/lib.linux-x86_64-3.9/MySQLdb复制MySQLdb/__init__.py->build/lib.linux-x86_64-3.9/MySQLdb复制MySQLdb/_exceptions.py->build/lib.linux-x86_64-3.9/MySQLdb复制MySQLdb/connections.py->build/lib.linux-x86_64-3.9/MySQLdb复制MySQLdb/converters.py->build/lib。linux-x86_64-3.9/MySQLdb复制MySQLdb/cursors.py->build/lib.linux-x86_64-3.9/MySQLdb复制MySQLdb/release.py->build/lib.linux-x86_64-3.9/MySQLdb复制MySQLdb/times。py->build/lib.linux-x86_64-3.9/MySQLdb创建build/lib.linux-x86_64-3.9/MySQLdb/constants复制MySQLdb/constants/__init__.py->build/lib.linux-x86_64-3.9/MySQLdb/常量复制MySQLdb/constants/CLIENT.py->build/lib.linux-x86_64-3.9/MySQLdb/constants复制MySQLdb/constants/CR.py->build/lib.linux-x86_64-3.9/MySQLdb/constants复制MySQLdb/constants/ER.py->build/lib.linux-x86_64-3.9/MySQLdb/constants复制MySQLdb/constants/FIELD_TYPE.py->build/lib.linux-x86_64-3.9/MySQLdb/constants复制MySQLdb/constants/FLAG.py->build/lib.linux-x86_64-3.9/MySQLdb/constants警告:build_py:字节编译被禁用,跳过。运行build_ext构建'MySQLdb._mysql'扩展创建build/temp.linux-x86_64-3.9创建build/temp.linux-x86_64-3.9/MySQLdbx86_64-linux-gnu-gcc-pthread-Wno-unused-result-Wsign-compare-DNDEBUG-g-fwrapv-O2-Wall-g-fstack-protector-strong-Wformat-Werror=format-security-g-fwrapv-O2-g-fstack-protector-strong-Wformat-Werror=format-security-Wdate-time-D_FORTIFY_SOURCE=2-fPIC-Dversion_info=(2,0,3,'final',0)-D__version__=2.0.3-I/usr/include/mysql-I/home/bot/.local/share/virtualenvs/django-twitter-IaucORjf/include-I/usr/include/python3.9-cMySQLdb/_mysql.c-obuild/temp.linux-x86_64-3.9/MySQLdb/_mysql.o-std=c99MySQLdb/_mysql.c:46:10:fatalerror:Python.h:没有那个文件或目录46|#include"Python.h"|^~~~~~~~~~编译终止。错误:逗号nd'/usr/bin/x86_64-linux-gnu-gcc'失败,退出代码为1----------------------------------------错误:命令出错,退出状态为1:/home/bot/.local/share/virtualenvs/django-twitter-IaucORjf/bin/python-u-c'importio,os,sys,setuptools,tokenize;sys.argv[0]='"'"'/tmp/pip-install-rq7aoqrc/mysqlclient_40fa5be227e344b0a851378f6a96cc9a/setup.py'"'"';__file__='"'"'/tmp/pip-install-rq7aoqrc/mysqlclient_40fa5be227e344b0a851378f6a96cc9a/setup.py'"'"';f=getattr(tokenize,'"'"'open'"'"',打开)(__file__)如果os.path.exists(__file__)elseio.StringIO('"'"'fromsetuptoolsimportsetup;setup()'"'"');code=f.read().replace('"'"'\r\n'"'"','"'"'\n'"'"');f.close();exec(编译(代码,__file__,'"'"'exec'"'"'))'安装--record/tmp/pip-record-n8yzv7f4/install-record.txt--single-version-externally-managed--compile--install-headers/home/bot/.local/share/virtualenvs/django-twitter-IaucORjf/include/site/python3.9/mysqlclient检查完整命令输出的日志。因为我用的是3.9,之前的命令是3.8对应的dev,所以找不到。使用如下命令解决问题sudoaptinstallpython3.9-dev