pip install mysqlclient 返回“致命错误 C1083:无法打开文件:‘mysql.h’:没有此文件或目录

2025-03-10 08:52:00
admin
原创
71
摘要:问题描述:这是这个问题:我尝试像这样安装 mysqlclientC:Usersamccommon349>pip install mysqlclient Collecting mysqlclient Using cached https://files.pythonhosted.org/package...

问题描述:

这是这个问题:我尝试像这样安装 mysqlclient

C:Usersamccommon349>pip install mysqlclient
Collecting mysqlclient
  Using cached https://files.pythonhosted.org/packages/ec/fd/83329b9d3e14f7344d1
cb31f128e6dbba70c5975c9e57896815dbb1988ad/mysqlclient-1.3.13.tar.gz
Installing collected packages: mysqlclient
  Running setup.py install for mysqlclient ... error
    Complete output from command c:/usersamccommon349appdatalocalprogramspythonpython36python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\AMCCOM~1\\AppData\\Local\\Temp\\pip-install-qcgo48hf\\mysqlclient\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('
', '
');f.close();exec(compile(code, __file__, 'exec'))" install --record C:UsersAMCCOM~1AppDataLocalTemppip-record-q4yoftj8install-record.txt --single-version-externally-managed --compile:

c:/usersamccommon349appdatalocalprogramspythonpython36libdistutilsdist.py:261: UserWarning: Unknown distribution option: 'long_description_content_type'
warnings.warn(msg)
running install
running build
running build_py
creating build
creating buildlib.win-amd64-3.6
copying _mysql_exceptions.py -> buildlib.win-amd64-3.6
creating buildlib.win-amd64-3.6MySQLdb
copying MySQLdb__init__.py -> buildlib.win-amd64-3.6MySQLdb
copying MySQLdbcompat.py -> buildlib.win-amd64-3.6MySQLdb
copying MySQLdbconnections.py -> buildlib.win-amd64-3.6MySQLdb
copying MySQLdbconverters.py -> buildlib.win-amd64-3.6MySQLdb
copying MySQLdbcursors.py -> buildlib.win-amd64-3.6MySQLdb
copying MySQLdb
elease.py -> buildlib.win-amd64-3.6MySQLdb
copying MySQLdb    imes.py -> buildlib.win-amd64-3.6MySQLdb
creating buildlib.win-amd64-3.6MySQLdbconstants
copying MySQLdbconstants__init__.py -> buildlib.win-amd64-3.6MySQLdbconstants
copying MySQLdbconstantsCLIENT.py -> buildlib.win-amd64-3.6MySQLdbconstants
copying MySQLdbconstantsCR.py -> buildlib.win-amd64-3.6MySQLdbconstants
copying MySQLdbconstantsER.py -> buildlib.win-amd64-3.6MySQLdbconstants
copying MySQLdbconstantsFIELD_TYPE.py -> buildlib.win-amd64-3.6MySQLdbconstants
copying MySQLdbconstantsFLAG.py -> buildlib.win-amd64-3.6MySQLdbconstants
copying MySQLdbconstantsREFRESH.py -> buildlib.win-amd64-3.6MySQLdbconstants
running build_ext
building '_mysql' extension
creating build    emp.win-amd64-3.6
creating build    emp.win-amd64-3.6Release
C:Program Files (x86)Microsoft Visual Studio7BuildToolsVCToolsMSVC.14.26428inHostX86x64cl.exe /c/nologo/Ox /W3 /GL /DNDEBUG /MD -Dversion_info=(1,3,13,'final',0) -D__version__=1.3.13 "-IC:Program Files (x86)MySQLMySQL Connector C 6.1include" -Ic:/usersamccommon349appdatalocalprogramspythonpython36include -Ic:/usersamccommon349appdatalocalprogramspythonpython36include "-IC:Program Files (x86)Microsoft Visual Studio7BuildToolsVCToolsMSVC.14.26428include" "-IC:Program Files (x86)Windows KitsNETFXSDK.6.1include/um" "-IC:Program Files (x86)Windows Kitsinclude.0.17134.0/ucrt" "-IC:Program Files (x86)Windows Kitsinclude.0.17134.0shared" "-IC:Program Files (x86)Windows Kitsinclude.0.17134.0/um" "-IC:ProgramFiles (x86)Windows Kitsinclude.0.17134.0winrt" "-IC:Program Files (x86)Windows Kitsinclude.0.17134.0cppwinrt" /Tc_mysql.c /Fobuild    emp.win-amd64-3.6Release_mysql.obj /Zl _mysql.c
_mysql.c(29): fatal error C1083: Cannot open include file: 'mysql.h': No such file or directory
  error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\VC\\Tools\\MSVC\\14.14.26428\\bin\\HostX86\d\\cl.exe' failed with exit status 2

我确保我拥有 Visual Studio 构建工具所需的所有文件,下载了 mysql-python 连接器,并更新了我的 pip 和设置工具。我完全是这方面的初学者,非常感激任何关于如何修复此错误的意见。


解决方案 1:

您可以使用https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient下载适用于您的 Python 版本的非官方 Windows 二进制文件。然后使用 pip 安装它。这样您就可以避免处理 Visual Studio 构建工具的麻烦。

只需下载最适合您的 mysqlclient.whl 文件。我认为对于你的情况,它将是

mysqlclient‑1.3.13‑cp36‑cp36m‑win_amd64.whl

然后运行

pip install "path to the downloaded .whl file"

解决方案 2:

在 64 位环境中尝试安装适用于 python32 的 mysqlclient 时出现此错误。卸载 python 并重新安装 64 位版本。然后 pip install mysqlclient 将正常运行。

解决方案 3:

好吧,这可能是我见过的最愚蠢的错误之一。

我有 Python 3.7.3 32 位以及最新的 pip3,我正在为我的 Python 安装轮子......我偶然发现了这个愚蠢的错误......

可能我的情况有点不同,但你可以通过仔细查看错误来解决它......起初似乎缺少了一些东西,你开始责怪你,Windows,32/64 位,列表还在不断增加..

退一步......退一步,只需阅读令人讨厌的红色错误消息...... 仔细阅读

就我而言,它是

ERROR: Command errored out with exit status 1:
     command: 'c:/usersmyUserNameappdatalocalprogramspythonpython37-32python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\MASTER~1\\AppData\\Local\\Temp\\pip-install-z7x81g2q\\mysqlclient\\setup.py'"'"'; __file__='"'"'C:\\Users\\MASTER~1\\AppData\\Local\\Temp\\pip-install-z7x81g2q\\mysqlclient\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'
'"'"', '"'"'
'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:UsersMASTER~1AppDataLocalTemppip-record-z1mvci5vinstall-record.txt' --single-version-externally-managed --compile
         cwd: C:UsersMASTER~1AppDataLocalTemppip-install-z7x81g2qmysqlclient\n    Complete output (30 lines):
    running install
    running build
    running build_py
    creating build
    creating buildlib.win32-3.7
    creating buildlib.win32-3.7MySQLdb
    copying MySQLdb__init__.py -> buildlib.win32-3.7MySQLdb
    copying MySQLdb_exceptions.py -> buildlib.win32-3.7MySQLdb
    copying MySQLdbcompat.py -> buildlib.win32-3.7MySQLdb
    copying MySQLdbconnections.py -> buildlib.win32-3.7MySQLdb
    copying MySQLdbconverters.py -> buildlib.win32-3.7MySQLdb
    copying MySQLdbcursors.py -> buildlib.win32-3.7MySQLdb
    copying MySQLdb
elease.py -> buildlib.win32-3.7MySQLdb
    copying MySQLdb    imes.py -> buildlib.win32-3.7MySQLdb
    creating buildlib.win32-3.7MySQLdbconstants
    copying MySQLdbconstants__init__.py -> buildlib.win32-3.7MySQLdbconstants
    copying MySQLdbconstantsCLIENT.py -> buildlib.win32-3.7MySQLdbconstants
    copying MySQLdbconstantsCR.py -> buildlib.win32-3.7MySQLdbconstants
    copying MySQLdbconstantsER.py -> buildlib.win32-3.7MySQLdbconstants
    copying MySQLdbconstantsFIELD_TYPE.py -> buildlib.win32-3.7MySQLdbconstants
    copying MySQLdbconstantsFLAG.py -> buildlib.win32-3.7MySQLdbconstants
    running build_ext
    building 'MySQLdb._mysql' extension
    creating build    emp.win32-3.7
    creating build    emp.win32-3.7Release
    creating build    emp.win32-3.7ReleaseMySQLdb
    C:Program Files (x86)Microsoft Visual Studio9BuildToolsVCToolsMSVC.21.27702inHostX86x86cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MT -Dversion_info=(1,4,2,'post',1) -D__version__=1.4.2.post1 "-IC:Program Files (x86)MySQLMySQL Connector C 6.1includemariadb" -Ic:/usersMyUserNameappdatalocalprogramspythonpython37-32include -Ic:/usersMyUserNameappdatalocalprogramspythonpython37-32include "-IC:Program Files (x86)Microsoft Visual Studio9BuildToolsVCToolsMSVC.21.27702include" "-IC:Program Files (x86)Windows Kitsinclude.0.17763.0/ucrt" "-IC:Program Files (x86)Windows Kitsinclude.0.17763.0shared" "-IC:Program Files (x86)Windows Kitsinclude.0.17763.0/um" "-IC:Program Files (x86)Windows Kitsinclude.0.17763.0winrt" "-IC:Program Files (x86)Windows Kitsinclude.0.17763.0cppwinrt" /TcMySQLdb/_mysql.c /Fobuild    emp.win32-3.7ReleaseMySQLdb/_mysql.obj /Zl /D_CRT_SECURE_NO_WARNINGS
    _mysql.c
    MySQLdb/_mysql.c(29): fatal error C1083: Cannot open include file: 'mysql.h': No such file or directory
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.21.27702\\bin\\HostX86\†\\cl.exe' failed with exit status 2
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:/usersMyUserNameappdatalocalprogramspythonpython37-32python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\MASTER~1\\AppData\\Local\\Temp\\pip-install-z7x81g2q\\mysqlclient\\setup.py'"'"'; __file__='"'"'C:\\Users\\MASTER~1\\AppData\\Local\\Temp\\pip-install-z7x81g2q\\mysqlclient\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'
'"'"', '"'"'
'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:UsersMASTER~1AppDataLocalTemppip-record-z1mvci5vinstall-record.txt' --single-version-externally-managed --compile Check the logs for full command output.

你读得仔细了吗?我假设你已经拥有了一切……构建工具、MySQL Connector C 6.1……你甚至将它移动到了 Program Files (x86)……那么它出了什么问题……?……

现在仔细看看

C:Program Files (x86)Microsoft Visual Studio9BuildToolsVCToolsMSVC.21.27702inHostX86x86cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MT -Dversion_info=(1,4,2,'post',1) -D__version__=1.4.2.post1 "-IC:Program Files (x86)MySQLMySQL Connector C 6.1includemariadb" -

我很确定你看到了...还是没有?....让我为你加粗

"-IC:Program Files (x86)MySQLMySQL Connector C 6.1includemariadb" -

mariadb

嗯,这不可能比这更愚蠢了……安装程序会查找 mariadb包含的内容以及后续的库,
只需转到 mariadb 网站并下载 MariaDB C/C++ 连接器并安装它...

嗯,这还没有结束..转到 C:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include 并创建文件夹 mariadb...然后复制粘贴 mariaDb 连接器安装包含文件夹中的内容,

再次不要走...转到 C:\Program Files (x86)\MySQL\MySQL Connector C 6.1\lib 并对lib文件夹再次执行相同的操作,

所以你应该有

C:Program Files (x86)MySQLMySQL Connector C 6.1includemariadb  

C:Program Files (x86)MySQLMySQL Connector C 6.1libmariadb  

现在点击pip3 install mysqlclient

并享受无烦扰的安装...结束

Successfully installed mysqlclient-1.4.2.post1

解决方案 4:

这就是解决我的问题的方法

  • 从此处安装 MySQL Connector/C(存档版本)

它可能安装在以下位置
C:Program FilesMySQLMySQL Connector C 6.1


  • 将整个文件夹复制MySQL Connector C 6.1C:Program Files (x86)MySQLMySQL Connector C 6.1


  • 尝试执行命令pip3 install mysqlclient

成功了吗?干得好!


不成功?


  • 从这里安装 MariaDB 连接器

可能安装在以下位置

C:Program FilesMariaDBMariaDB Connector C 64-bit

  • 复制内容

C:Program FilesMariaDBMariaDB Connector C 64-bitinclude

并粘贴到文件夹中。将其命名为mariadb并粘贴到位置

C:Program Files (x86)MySQLMySQL Connector C 6.1include


  • 复制内容

C:Program FilesMariaDBMariaDB Connector C 64-bitlib

并将其粘贴到文件夹中mariadb,并将其命名为

`C:Program Files (x86)MySQLMySQL Connector C 6.1lib`

  • 尝试执行命令pip3 install mysqlclient

这对我有用

解决方案 5:

我遇到了这个问题(完全相同的错误)并尝试了上面提到的所有解决方案,但都没有用(至少对我来说),实际上我正要为这个问题而烦恼,直到我以一种非常奇怪、简单和愚蠢的方式找到了解决方案!!

我采取了以下步骤,问题就解决了,生活又变得甜蜜起来。

首先我MySQL Connector/C从这里安装

第二(安装完成后)我将文件MySQL Connector C 6.1夹复制 Program files/MySQL`Program files (x86)/MySQL`

MySQL请注意,如果文件夹不存在,您可能必须创建该文件夹Program files (x86)(对我来说它不存在)

就这么简单,它对我来说是有效的,对于一些(或所有)64 位 Windows,pip 或更可能的mysqlclient安装脚本只在Program files (x86)文件夹中搜索一些 MySQL 文件(例如“mysql.h”)并且不搜索Program files,因为没有找到任何东西,Program files (x86)引发了非常愚蠢的错误! ! 不是吗?

解决方案 6:

我在从 pip 安装 mysqlclient 时遇到了同样的问题,无需手动下载.whl 文件,您可以指定所需的包的版本。以下是我的解决方案:

pip install mysqlclient==1.4.6

谢谢。

解决方案 7:

上述解决方案对我都不起作用。显然,我不得不将我的 Python 从 降级3.7.x3.6.4,这为我解决了问题。下载链接python=3.6.4

我建议为此创建一个新的虚拟环境,而不是卸载主 Python。有关如何创建的详尽文档可venv 在此处找到。

解决方案 8:

这是 Windows 10 上 64 位版本的 Python 的问题。以下内容为我修复了该问题。

  1. 安装适用于 Windows 的 32 位版本的 Python(当前版本为 3.7.1)

  2. 安装适用于 C++ 的Visual Studio 构建工具
    https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2017

  3. https://downloads.mysql.com/archives/cc/安装 32 位 mysql 连接器版本 6.1.11

此后,我就能够使用 来安装 mysqlclient 了pip install mysqlclient

希望有人能想出一个更好的解决方案,不需要降级到 32 位,因为这不是一个好的解决方案,它只是有效。我找到了一种解决 mysql 问题的方法,但在尝试安装频道时再次遇到了问题。似乎 python 64 位正在寻找 32 位库而不是 Windows 上的 64 位库。到目前为止,这个解决方案已经解决了我在 Windows 上构建 Python 的所有问题。

解决方案 9:

我在Windows 10上使用Python 3.12时遇到了类似的错误

PS C:Usersjuanf> pip install mysqlclient
Collecting mysqlclient
  Using cached mysqlclient-2.2.0.tar.gz (89 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: mysqlclient
  Building wheel for mysqlclient (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Building wheel for mysqlclient (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [46 lines of output]
      # Options for building extention module:
        library_dirs: ['C:/mariadb-connector\\lib\\mariadb', 'C:/mariadb-connector\\lib']
        libraries: ['kernel32', 'advapi32', 'wsock32', 'shlwapi', 'Ws2_32', 'crypt32', 'secur32', 'bcrypt', 'mariadbclient']
        extra_link_args: ['/MANIFEST']
        include_dirs: ['C:/mariadb-connector\\include\\mariadb', 'C:/mariadb-connector\\include']
        extra_objects: []
        define_macros: [('version_info', (2, 2, 0, 'final', 0)), ('__version__', '2.2.0')]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating buildlib.win-amd64-cpython-312
      creating buildlib.win-amd64-cpython-312MySQLdb
      copying srcMySQLdbconnections.py -> buildlib.win-amd64-cpython-312MySQLdb
      copying srcMySQLdbconverters.py -> buildlib.win-amd64-cpython-312MySQLdb
      copying srcMySQLdbcursors.py -> buildlib.win-amd64-cpython-312MySQLdb
      copying srcMySQLdb
elease.py -> buildlib.win-amd64-cpython-312MySQLdb
      copying srcMySQLdb    imes.py -> buildlib.win-amd64-cpython-312MySQLdb
      copying srcMySQLdb_exceptions.py -> buildlib.win-amd64-cpython-312MySQLdb
      copying srcMySQLdb__init__.py -> buildlib.win-amd64-cpython-312MySQLdb
      creating buildlib.win-amd64-cpython-312MySQLdbconstants
      copying srcMySQLdbconstantsCLIENT.py -> buildlib.win-amd64-cpython-312MySQLdbconstants
      copying srcMySQLdbconstantsCR.py -> buildlib.win-amd64-cpython-312MySQLdbconstants
      copying srcMySQLdbconstantsER.py -> buildlib.win-amd64-cpython-312MySQLdbconstants
      copying srcMySQLdbconstantsFIELD_TYPE.py -> buildlib.win-amd64-cpython-312MySQLdbconstants
      copying srcMySQLdbconstantsFLAG.py -> buildlib.win-amd64-cpython-312MySQLdbconstants
      copying srcMySQLdbconstants__init__.py -> buildlib.win-amd64-cpython-312MySQLdbconstants
      running egg_info
      writing srcmysqlclient.egg-infoPKG-INFO
      writing dependency_links to srcmysqlclient.egg-infodependency_links.txt
      writing top-level names to srcmysqlclient.egg-info    op_level.txt
      reading manifest file 'srcmysqlclient.egg-infoSOURCES.txt'
      reading manifest template 'MANIFEST.in'
      adding license file 'LICENSE'
      writing manifest file 'srcmysqlclient.egg-infoSOURCES.txt'
      copying srcMySQLdb_mysql.c -> buildlib.win-amd64-cpython-312MySQLdb
      running build_ext
      building 'MySQLdb._mysql' extension
      creating build    emp.win-amd64-cpython-312
      creating build    emp.win-amd64-cpython-312Release
      creating build    emp.win-amd64-cpython-312Releasesrc
      creating build    emp.win-amd64-cpython-312ReleasesrcMySQLdb
      "C:Program FilesMicrosoft Visual Studio‚2CommunityVCToolsMSVC.37.32822inHostX86x64cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD "-Dversion_info=(2, 2, 0, 'final', 0)" -D__version__=2.2.0 -IC:/mariadb-connectorincludemariadb -IC:/mariadb-connectorinclude -IC:Python312include -IC:Python312Include "-IC:Program FilesMicrosoft Visual Studio‚2CommunityVCToolsMSVC.37.32822include" "-IC:Program FilesMicrosoft Visual Studio‚2CommunityVCToolsMSVC.37.32822ATLMFCinclude" "-IC:Program FilesMicrosoft Visual Studio‚2CommunityVCAuxiliaryVSinclude" "-IC:Program Files (x86)Windows Kitsinclude.0.22621.0/ucrt" "-IC:Program Files (x86)Windows Kits\\include.0.22621.0\/um" "-IC:Program Files (x86)Windows Kits\\include.0.22621.0\\shared" "-IC:Program Files (x86)Windows Kits\\include.0.22621.0\\winrt" "-IC:Program Files (x86)Windows Kits\\include.0.22621.0\\cppwinrt" "-IC:Program Files (x86)Windows KitsNETFXSDK.8include/um" /Tcsrc/MySQLdb/_mysql.c /Fobuild    emp.win-amd64-cpython-312Releasesrc/MySQLdb/_mysql.obj
      _mysql.c
      src/MySQLdb/_mysql.c(29): fatal error C1083: Cannot open include file: 'mysql.h': No such file or directory
      error: command 'C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.37.32822\\bin\\HostX86\d\\cl.exe' failed with exit code 2
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for mysqlclient
Failed to build mysqlclient
ERROR: Could not build wheels for mysqlclient, which is required to install pyproject.toml-based projects

[notice] A new release of pip is available: 23.2.1 -> 23.3.1
[notice] To update, run: python.exe -m pip install --upgrade pip

过了一段时间我发现了两个可能的解决方案:

  1. 从 mysqlclient 的官方 pypi 页面 ( https://pypi.org/project/mysqlclient/#files )下载 .whl 文件,并使用pip install "your whl file location"

  2. 从 ( https://mariadb.com/downloads/connectors/ )下载适用于您的操作系统的 MariaDB 连接器并安装它。我注意到 mariadb 连接器在不同于其默认安装的文件夹中被搜索library_dirs: ['C:/mariadb-connector\lib\mariadb', 'C:/mariadb-connector\lib']。因此,将安装文件从 移动C:Program FilesMariaDBMariaDB Connector CC:mariadb-connector。确保您还安装了 Microsft Visual Studio C++ Build Tools(为此下载 Visual Studio Community)。之后执行pip install mysqlclient

我使用的是第二个选项,但两个选项都应该可以。

编辑:

您需要重新安装 maria DB 连接器(在默认文件夹中)以使库正常工作。

解决方案 10:

为了解决这个问题,我去了这个页面

在此处输入图片描述

并下载了mysqlclient‑1.4.6‑pp373‑pypy36_pp73‑win32.whl

然后,将其放在特定文件夹中,在其中打开终端,激活虚拟环境venv并运行

pip install mysqlclient-1.4.6-cp39-cp39-win_amd64.whl

在此处输入图片描述

解决方案 11:

有时错误也是解释器的错误,我的情况就是如此。我使用的是 3.8 版 Python,并将其安装在 D:/,因此安装不正确。

因此我将其卸载并再次正确安装,并且它起作用了。

解决方案 12:

我的要求是版本 1.4.6,所以这个对我有用。也在这里分享了https://stackoverflow.com/a/74758867/9674385

pip 安装 mysqlclient==1.4.6

解决方案 13:

阅读错误,它正在寻找 mariadb 连接器。从https://mariadb.com/downloads/connectors/connectors-data-access/c-connector/-IC:/mariadb-connectorincludemariadb下载 mariadb-connector“C 连接器”并安装。转到安装文件夹并将文件夹复制到它在你的情况下寻找的位置。所以你应该把它粘贴进去并重命名为,这样它就可以找到它。C:Program FilesMariaDBMariaDB Connector C 64-bit`MariaDB Connector C 64-bit-IC:/mariadb-connectorincludemariadbC:/`mariadb-connector

解决方案 14:

我不明白为什么没有人看过文档,只需安装MariaDB Connector并将环境变量设置MYSQLCLIENT_CONNECTOR为 mariadb 连接器(不是 mariadb)的根路径即可。这是唯一适用于我的 Windows 11 PC 的方法

解决方案 15:

浪费了很多时间来解决这个错误,至少我找到了对我有用的解决方案。

当我尝试安装 MYSQL 客户端时

pip install mysqlclient

第一个错误

MySQLdb/_mysql.c(29): 致命错误 C1083: 无法打开包含文件:‘mysql.h’: 没有此文件或目录


并尝试安装 Django Channels

pip install -U channels

第二个错误

错误:需要 Microsoft Visual C++ 14.0。使用“Microsoft Visual C++ Build Tools”获取:https://visualstudio.microsoft.com/downloads/

下载构建工具:
Microsoft Build Tools

Stack overflow:
如何安装/选择所需的构建工具

已安装构建工具。(祝您编码愉快)


@Ralph Ritoch解决方案对我以及其他遇到 Mysql 客户端错误的人都有效。

但我还安装了 Django Channels,因此我遵循了下面提到的这些步骤

请按照以下步骤操作

  1. Windows 10 64 位

  2. Python 64 位 3.7.3

  3. mysql-连接器-c-6.1.11-winx64

  4. 构建工具

我还安装了 Django Channels 2.2.0,没有出现任何错误。

成功安装mysqlclient


(笔记)

MySQL 连接器已安装到 x86 目录中

将 c:\Program Files\MySQL\MySQL Connector C 6.0.2\ 目录复制到 c:\Program Files (x86)\MySQL\MySQL Connector C 6.1\

所以我没有改变 MySQL Connector 的目录。(你也可以检查一下)

也许对你有用!

更改目录的其他 Stack 解决方案


可能的原因

为什么我们会得到错误。

  1. Python 32/64 位版本

  2. MySQL 连接器 32/64 位版本

  3. 目录问题

  4. Windows 32/64 位版本

  5. 未安装构建工具(如果需要获取 Microsoft Visual C++ 14.0)


感谢所有发布解决方案的人。

解决方案 16:

我想对约翰的回答发表评论,但我的评论太长了,所以我不得不再做一次回答。很抱歉。

John,这帮了我大忙,谢谢。不好好阅读日志对很多人来说都是一个坏习惯,包括我自己。

但是我没有下载 mariadb 连接器(或在网上搜索预建的 wheel),而是设法使用 oracle 的 mysql 连接器来完成此操作。我更喜欢使用符号链接而不是复制文件。以下是我使用 Windows 10 x64、Python 3.8 x64 和 oracle 的 mysql 连接器 x64 执行的操作:

# run this on an elevated command prompt if your user does not have permission to make symbolic links
# download and install https://downloads.mysql.com/archives/c-c/
mklink /d "C:Program FilesMySQLMySQL Connector C 6.1includemariadb" "C:Program FilesMySQLMySQL Connector C 6.1includemysql"
mklink /d "C:Program Files (x86)MySQL" "C:Program FilesMySQL"
mklink /d "C:Program FilesMySQLMySQL Connector C 6.1libmariadb" "C:Program FilesMySQLMySQL Connector C 6.1libs14"
mklink "C:Program FilesMySQLMySQL Connector C 6.1libs14mariadbclient.lib" "C:Program FilesMySQLMySQL Connector C 6.1libs14mysqlclient.lib"
SET INCLUDE=C:Program FilesMySQLMySQL Connector C 6.1include;%INCLUDE%
python3 -m pip install mysqlclient

就是这样。

解决方案 17:

感谢大家的回答,但这不足以解决我的问题。不过,它让我走上了正确的道路 :)。为了解决缺少 sys/types.h 的错误,我必须将此 types.h 文件从“c:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0/ucrt\sys\”复制到“c:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include\mariadb\sys\”。然后我终于可以安装 mysqlclient 了。

解决方案 18:

对我来说,pip install mysqlclient这是抛出错误......

MySQLdb/_mysql.c(29): fatal error C1083: Cannot open include file: 'mysql.h': No such file or directory
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.20.27508\\bin\\HostX86\†\\cl.exe' failed with exit status 2

看来 mysqlclient 是 64 位的。因此我强制 Python 和 pip 从 64 位目录执行。

明确地...

run python -m venv myvemv and pip install -r requirements.txt

运行以下命令...

C:UsersmrAppDataLocalProgramsPythonPython37python -m venv [path to your virtual env goes here]

C:UsersmrAppDataLocalProgramsPythonPython37Scriptspip install -r requirements.txt

解决方案 19:

我也尝试过在 Django 项目中使用同样的方法。我尝试使用:

pip install mysql-python

但出现了以下错误:
'mysql.h': No such file or directory

在摆弄 requirements.txt 后,又出现了另一个错误

  Downloading https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip (108kB) 
    Complete output from command python setup.py egg_info: 
    Traceback (most recent call last): 
      File "<string>", line 1, in <module> 
      File "/tmp/pip-install-43_6cfva/MySQL-python/setup.py", line 13, in <module> 
        from setup_posix import get_config 
      File "/tmp/pip-install-43_6cfva/MySQL-python/setup_posix.py", line 2, in <module> 
        from ConfigParser import SafeConfigParser 
    ModuleNotFoundError: No module named 'ConfigParser' 

最后使用这个对我有用
pip install mysql-connector

import mysql.connector

解决方案 20:

还有其他方法可以将mysqlclient安装到您的系统中,我无法直接通过命令提示符安装它,它显示:

启动器中发生致命错误:无法创建进程

尝试了其他几种替代方案并得到了解决方案:

  • 点击开始

  • 搜索 python 并点击打开文件位置
    点击打开文件位置

  • 3.单击python(版本例如=2.7,3.8,3.9 ...等)
    右键单击并打开文件位置

  • 4.点击脚本

  • 5.转到文件资源管理器顶部的路径并输入 cmd

    1. 命令提示符打开后,输入pip install mysqlclient

  • 7.安装开始,现在你的系统中有了mysqlclient

解决方案 21:

我们可以做很多事情,但是如果我们错过在 64 位环境中执行 python 64 位,则设置将无法完成。

所以,如果我们的 Windows 是 64 位的,我们必须确认 Python 64 位。

要查看您是处于 64 位还是 32 位,请在命令提示符中运行 python 命令并查看如下所示的结果:

检查 python 是 32 位还是 64 位

解决方案 22:

只是想分享我如何解决这个问题。我将其降级到 Python 版本 3.10,而不是使用新版本 3.12。我尝试了上述所有解决方案,但都没有解决问题。所以我尝试复制笔记本电脑上的所有设置并将其复制到台式机上,这解决了我的问题。也许将来他们会在 3.12 上修复它。但就目前而言,它运行良好。

fatal error C1083: Cannot open include file: 'mysql.h'顺便说一句,我遇到的第一个错误是 Microsoft Visual 14 或更高版本,修复该问题后,这是一个快速修复。当我安装所有必需品时,该错误出现

我尝试下载 .whl 文件,但仍然不起作用。也许这也会帮助其他仍然遇到此问题的人。顺便说一句,几乎所有托管 Python/Django 应用程序的服务器都具有较低的 Python 版本。

解决方案 23:

前面的答案并不适用于所有人。仔细检查错误。有时编译器会尝试包含目录C:/mariadb-connector/include/mariadb

就我而言,错误消息如下:-IC:/mariadb-connectorincludemariadb
这是我所做的:

  1. 安装了 mariadb c 连接器

  2. 在 C 盘根目录下创建一个名为 mariadb-connector 的文件夹

  3. 将内容粘贴到我创建的mariadb-connectorC:Program FilesMariaDBMariaDB Connector C 64-bit中。

而且它确实有效。

解决方案 24:

尝试:

pip install --only-binary :all: mysqlclient

解决方案 25:

解决方案是设置以下环境变量 MYSQLCLIENT_CFLAGS 和 MYSQLCLIENT_LDFLAGS CFLAGS 应该是“-I <mysql/include 文件夹的路径> 例如在 linux 中导出 MYSQLCLIENT_CFLAGS=-I/usr/test/mysql8.0.36/include 和 MYSQLCLIENT_LDFLAGS=-L/usr/test/mysql8.0.36/lib

解决方案 26:

使用以下命令安装最新版本:

pip install mysqlclient

使用 1.4.6 版本时,一次又一次失败。但是,删除版本要求后,安装 2.1.1 时就不会出现错误。

解决方案 27:

我刚刚将我的 pyhton 版本降级到 3.8,它运行得很好

解决方案 28:

在命令行中,只需输入:

python --

而不是:

python --version

(这将显示有关版本的更多详细信息,包括它是 32 位还是 64 位)

相关推荐
  政府信创国产化的10大政策解读一、信创国产化的背景与意义信创国产化,即信息技术应用创新国产化,是当前中国信息技术领域的一个重要发展方向。其核心在于通过自主研发和创新,实现信息技术应用的自主可控,减少对外部技术的依赖,并规避潜在的技术制裁和风险。随着全球信息技术竞争的加剧,以及某些国家对中国在科技领域的打压,信创国产化显...
工程项目管理   4008  
  为什么项目管理通常仍然耗时且低效?您是否还在反复更新电子表格、淹没在便利贴中并参加每周更新会议?这确实是耗费时间和精力。借助软件工具的帮助,您可以一目了然地全面了解您的项目。如今,国内外有足够多优秀的项目管理软件可以帮助您掌控每个项目。什么是项目管理软件?项目管理软件是广泛行业用于项目规划、资源分配和调度的软件。它使项...
项目管理软件   2751  
  本文介绍了以下10款项目管理软件工具:禅道项目管理软件、Freshdesk、ClickUp、nTask、Hubstaff、Plutio、Productive、Targa、Bonsai、Wrike。在当今快速变化的商业环境中,项目管理已成为企业成功的关键因素之一。然而,许多企业在项目管理过程中面临着诸多痛点,如任务分配不...
项目管理系统   86  
  本文介绍了以下10款项目管理软件工具:禅道项目管理软件、Monday、TeamGantt、Filestage、Chanty、Visor、Smartsheet、Productive、Quire、Planview。在当今快速变化的商业环境中,项目管理已成为企业成功的关键因素之一。然而,许多项目经理和团队在管理复杂项目时,常...
开源项目管理工具   97  
  本文介绍了以下10款项目管理软件工具:禅道项目管理软件、Smartsheet、GanttPRO、Backlog、Visor、ResourceGuru、Productive、Xebrio、Hive、Quire。在当今快节奏的商业环境中,项目管理已成为企业成功的关键因素之一。然而,许多企业在选择项目管理工具时常常面临困惑:...
项目管理系统   85  
热门文章
项目管理软件有哪些?
曾咪二维码

扫码咨询,免费领取项目管理大礼包!

云禅道AD
禅道项目管理软件

云端的项目管理软件

尊享禅道项目软件收费版功能

无需维护,随时随地协同办公

内置subversion和git源码管理

每天备份,随时转为私有部署

免费试用