I installed 0618c8826826f8 in mysqlclient , and encountered many errors. The reason is that mysqlclient needs to rely on some dynamic link libraries, and it is related to the python version.

Environmental introduction:
ubuntu20 comes with python3.8, but I installed python3.9 myself

Use the command: sudo apt install python3.9 to install python3.9

Subtitle:

  • "OSError: mysql_config not found" error occurs when installing Python mysqlclient
  • Install python3.9-dev across system python versions
  • Install python3.9-dev for ubuntu20
  • The python that comes with ubuntu is 3.8, how to install mysqlclient for 3.9

Error one:

Complete error message

    ERROR: Command errored out with exit status 1:
     command: /home/bot/.local/share/virtualenvs/django-twitter-IaucORjf/bin/python -c 'import 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__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-ksb3c8ih
         cwd: /tmp/pip-install-ad2qu_uy/mysqlclient_df40fd48e0dc469e8a102567b171b787/
    Complete output (15 lines):
    /bin/sh: 1: mysql_config: not found
    /bin/sh: 1: mariadb_config: not found
    /bin/sh: 1: mysql_config: not found
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-ad2qu_uy/mysqlclient_df40fd48e0dc469e8a102567b171b787/setup.py", line 15, in <module>
        metadata, options = get_config()
      File "/tmp/pip-install-ad2qu_uy/mysqlclient_df40fd48e0dc469e8a102567b171b787/setup_posix.py", line 70, in get_config
        libs = mysql_config("libs")
      File "/tmp/pip-install-ad2qu_uy/mysqlclient_df40fd48e0dc469e8a102567b171b787/setup_posix.py", line 31, in mysql_config
        raise OSError("{} not found".format(_mysql_config_path))
    OSError: mysql_config not found
    mysql_config --version
    mariadb_config --version
    mysql_config --libs
    ----------------------------------------
WARNING: Discarding https://pypi.tuna.tsinghua.edu.cn/packages/3c/df/59cd2fa5e48d0804d213bdcb1acb4d08c403b61c7ff7ed4dd4a6a2deb3f7/mysqlclient-2.0.3.tar.gz#sha256=f6ebea7c008f155baeefe16c56cd3ee6239f7a5a9ae42396c2f1860f08a7c432 (from https://pypi.tuna.tsinghua.edu.cn/simple/mysqlclient/) (requires-python:>=3.5). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
ERROR: Could not find a version that satisfies the requirement mysqlclient==2.0.3 (from versions: 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: No matching distribution found for mysqlclient==2.0.3

Solution:

sudo apt install libmysqlclient-dev python3-dev
If the version of the python interpreter you use is the same as the python version that comes with the system, there is no problem.

If you are not using the python interpreter that comes with the system (the same version is no problem), continue to look down

Error two:

   ERROR: Command errored out with exit status 1:
     command: /home/bot/.local/share/virtualenvs/django-twitter-IaucORjf/bin/python -u -c 'import io, 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__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; 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/.local/share/virtualenvs/django-twitter-IaucORjf/include/site/python3.9/mysqlclient
         cwd: /tmp/pip-install-rq7aoqrc/mysqlclient_40fa5be227e344b0a851378f6a96cc9a/
    Complete output (46 lines):
    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')]
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.9
    creating build/lib.linux-x86_64-3.9/MySQLdb
    copying MySQLdb/__init__.py -> build/lib.linux-x86_64-3.9/MySQLdb
    copying MySQLdb/_exceptions.py -> build/lib.linux-x86_64-3.9/MySQLdb
    copying MySQLdb/connections.py -> build/lib.linux-x86_64-3.9/MySQLdb
    copying MySQLdb/converters.py -> build/lib.linux-x86_64-3.9/MySQLdb
    copying MySQLdb/cursors.py -> build/lib.linux-x86_64-3.9/MySQLdb
    copying MySQLdb/release.py -> build/lib.linux-x86_64-3.9/MySQLdb
    copying MySQLdb/times.py -> build/lib.linux-x86_64-3.9/MySQLdb
    creating build/lib.linux-x86_64-3.9/MySQLdb/constants
    copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-3.9/MySQLdb/constants
    copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-3.9/MySQLdb/constants
    copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-3.9/MySQLdb/constants
    copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-3.9/MySQLdb/constants
    copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-3.9/MySQLdb/constants
    copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-3.9/MySQLdb/constants
    warning: build_py: byte-compiling is disabled, skipping.
    
    running build_ext
    building 'MySQLdb._mysql' extension
    creating build/temp.linux-x86_64-3.9
    creating build/temp.linux-x86_64-3.9/MySQLdb
    x86_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 -c MySQLdb/_mysql.c -o build/temp.linux-x86_64-3.9/MySQLdb/_mysql.o -std=c99
    MySQLdb/_mysql.c:46:10: fatal error: Python.h: 没有那个文件或目录
       46 | #include "Python.h"
          |          ^~~~~~~~~~
    compilation terminated.
    error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /home/bot/.local/share/virtualenvs/django-twitter-IaucORjf/bin/python -u -c 'import io, 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__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; 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/.local/share/virtualenvs/django-twitter-IaucORjf/include/site/python3.9/mysqlclient Check the logs for full command output.

Because I used 3.9, the previous command installed the dev corresponding to 3.8, so I can’t find it

Use the following command to solve the problem

sudo apt install  python3.9-dev

universe_king
3.4k 声望680 粉丝