我正在try 使用以下工具安装mysqlclient

PIP安装mysqlClient 但面对以下错误

Collecting mysqlclient
  Using cached mysqlclient-2.1.1.tar.gz (88 kB)
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: mysqlclient
  Building wheel for mysqlclient (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /home/pixarsart/PycharmProjects/video_slicing/venv/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-uljhxj0e/mysqlclient_bcf14369053645289dd7e777e689db38/setup.py'"'"'; __file__='"'"'/tmp/pip-install-uljhxj0e/mysqlclient_bcf14369053645289dd7e777e689db38/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'"'"'))' bdist_wheel -d /tmp/pip-wheel-r6zmjoeu
       cwd: /tmp/pip-install-uljhxj0e/mysqlclient_bcf14369053645289dd7e777e689db38/
  Complete output (43 lines):
  mysql_config --version
  ['8.0.31']
  mysql_config --libs
  ['-L/usr/lib/x86_64-linux-gnu', '-lmysqlclient', '-lpthread', '-ldl', '-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,1,1,'final',0)"), ('__version__', '2.1.1')]
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.11
  creating build/lib.linux-x86_64-3.11/MySQLdb
  copying MySQLdb/__init__.py -> build/lib.linux-x86_64-3.11/MySQLdb
  copying MySQLdb/_exceptions.py -> build/lib.linux-x86_64-3.11/MySQLdb
  copying MySQLdb/connections.py -> build/lib.linux-x86_64-3.11/MySQLdb
  copying MySQLdb/converters.py -> build/lib.linux-x86_64-3.11/MySQLdb
  copying MySQLdb/cursors.py -> build/lib.linux-x86_64-3.11/MySQLdb
  copying MySQLdb/release.py -> build/lib.linux-x86_64-3.11/MySQLdb
  copying MySQLdb/times.py -> build/lib.linux-x86_64-3.11/MySQLdb
  creating build/lib.linux-x86_64-3.11/MySQLdb/constants
  copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-3.11/MySQLdb/constants
  copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-3.11/MySQLdb/constants
  copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-3.11/MySQLdb/constants
  copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-3.11/MySQLdb/constants
  copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-3.11/MySQLdb/constants
  copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-3.11/MySQLdb/constants
  running build_ext
  creating build/temp.linux-x86_64-3.11
  creating build/temp.linux-x86_64-3.11/MySQLdb
  x86_64-linux-gnu-gcc -pthread -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -Dversion_info=(2,1,1,'final',0) -D__version__=2.1.1 -I/usr/include/mysql -I/home/pixarsart/PycharmProjects/video_slicing/venv/include -I/usr/include/python3.11 -c MySQLdb/_mysql.c -o build/temp.linux-x86_64-3.11/MySQLdb/_mysql.o -std=c99
  MySQLdb/_mysql.c:46:10: fatal error: Python.h: No such file or directory
     46 | #include "Python.h"
        |          ^~~~~~~~~~
  compilation terminated.
  error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
  ----------------------------------------
  ERROR: Failed building wheel for mysqlclient
  Running setup.py clean for mysqlclient
Failed to build mysqlclient
Installing collected packages: mysqlclient
    Running setup.py install for mysqlclient ... error
    ERROR: Command errored out with exit status 1:
     command: /home/pixarsart/PycharmProjects/video_slicing/venv/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-uljhxj0e/mysqlclient_bcf14369053645289dd7e777e689db38/setup.py'"'"'; __file__='"'"'/tmp/pip-install-uljhxj0e/mysqlclient_bcf14369053645289dd7e777e689db38/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-x5dprlcj/install-record.txt --single-version-externally-managed --compile --install-headers /home/pixarsart/PycharmProjects/video_slicing/venv/include/site/python3.11/mysqlclient
         cwd: /tmp/pip-install-uljhxj0e/mysqlclient_bcf14369053645289dd7e777e689db38/
    Complete output (45 lines):
    mysql_config --version
    ['8.0.31']
    mysql_config --libs
    ['-L/usr/lib/x86_64-linux-gnu', '-lmysqlclient', '-lpthread', '-ldl', '-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,1,1,'final',0)"), ('__version__', '2.1.1')]
    running install
    /home/pixarsart/PycharmProjects/video_slicing/venv/lib/python3.11/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
      warnings.warn(
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.11
    creating build/lib.linux-x86_64-3.11/MySQLdb
    copying MySQLdb/__init__.py -> build/lib.linux-x86_64-3.11/MySQLdb
    copying MySQLdb/_exceptions.py -> build/lib.linux-x86_64-3.11/MySQLdb
    copying MySQLdb/connections.py -> build/lib.linux-x86_64-3.11/MySQLdb
    copying MySQLdb/converters.py -> build/lib.linux-x86_64-3.11/MySQLdb
    copying MySQLdb/cursors.py -> build/lib.linux-x86_64-3.11/MySQLdb
    copying MySQLdb/release.py -> build/lib.linux-x86_64-3.11/MySQLdb
    copying MySQLdb/times.py -> build/lib.linux-x86_64-3.11/MySQLdb
    creating build/lib.linux-x86_64-3.11/MySQLdb/constants
    copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-3.11/MySQLdb/constants
    copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-3.11/MySQLdb/constants
    copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-3.11/MySQLdb/constants
    copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-3.11/MySQLdb/constants
    copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-3.11/MySQLdb/constants
    copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-3.11/MySQLdb/constants
    running build_ext
    creating build/temp.linux-x86_64-3.11
    creating build/temp.linux-x86_64-3.11/MySQLdb
    x86_64-linux-gnu-gcc -pthread -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -Dversion_info=(2,1,1,'final',0) -D__version__=2.1.1 -I/usr/include/mysql -I/home/pixarsart/PycharmProjects/video_slicing/venv/include -I/usr/include/python3.11 -c MySQLdb/_mysql.c -o build/temp.linux-x86_64-3.11/MySQLdb/_mysql.o -std=c99
    MySQLdb/_mysql.c:46:10: fatal error: Python.h: No such file or directory
       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/pixarsart/PycharmProjects/video_slicing/venv/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-uljhxj0e/mysqlclient_bcf14369053645289dd7e777e689db38/setup.py'"'"'; __file__='"'"'/tmp/pip-install-uljhxj0e/mysqlclient_bcf14369053645289dd7e777e689db38/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-x5dprlcj/install-record.txt --single-version-externally-managed --compile --install-headers /home/pixarsart/PycharmProjects/video_slicing/venv/include/site/python3.11/mysqlclient Check the logs for full command output.

有没有猜想,这个问题怎么解决?

我试图在互联网上探索不同的解决方案,但无法解决.我也试过这个stackoverflow answer.但没有得到任何运气.

推荐答案

try 此解决方案:

您可以使用pymysql而不是mysqlclient

Install pymysql
pip install pymysql

修改init.py文件

import pymysql

pymysql.install_as_MySQLdb()

你可以开始你的项目了

Python相关问答推荐

ModuleNotFound错误:没有名为flags.State的模块; flags不是包

使用索引列表列表对列进行切片并获取行方向的向量长度

如何记录脚本输出

图像 pyramid .难以创建所需的合成图像

如何在Python中并行化以下搜索?

如何从.cgi网站刮一张表到rame?

如何使用表达式将字符串解压缩到Polars DataFrame中的多个列中?

将JSON对象转换为Dataframe

计算分布的标准差

如何从列表框中 Select 而不出错?

如何从pandas DataFrame中获取. groupby()和. agg()之后的子列?

递归函数修饰器

使用tqdm的进度条

BeatuifulSoup从欧洲志愿者服务中获取数据和解析:一个从EU-Site收集机会的小铲子

替换包含Python DataFrame中的值的<;

如何在不不断遇到ChromeDriver版本错误的情况下使用Selify?

来自任务调度程序的作为系统的Python文件

Python:使用asyncio.StreamReader.readline()读取长行

更新-如何与一个我无法使用python获得的按钮进行交互-Selify?

如何从多个词典中制作Pandas 数据帧?