关于python:pip install mysqlclient返回“严重错误C1083:无法打开文件:’mysql.h’:没有这样的文件或目录

pip install mysqlclient returns "fatal error C1083: Cannot open file: 'mysql.h': No such file or directory

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

C: Users amccommon349> pip安装mysqlclient
收集mysqlclient
使用缓存的https://files.pythonhosted.org/packages/ec/fd/83329b9d3e14f7344d1
cb31f128e6dbba70c5975c9e57896815dbb1988ad / mysqlclient-1.3.13.tar.gz

安装收集的软件包:mysqlclient

正在运行setup.py install for mysqlclient ...错误

1
2
3
4
Complete output from command c:\users\amccommon349\appdata\local\programs\python\python36\python.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:\Users\AMCCOM~1\AppData\Local\Temp\pip-record-q4yoftj8\install-record.txt --single-version-externally-managed --compile:

c: users amccommon349 appdata local programs python python36 lib distutils d
ist.py:261:用户警告:未知分发选项:'long_description_content_
类型'

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  warnings.warn(msg)
running install
running build
running build_py
creating build
creating build\lib.win-amd64-3.6
copying _mysql_exceptions.py -> build\lib.win-amd64-3.6
creating build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\__init__.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\compat.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\connections.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\converters.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\cursors.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb
elease.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\times.py -> build\lib.win-amd64-3.6\MySQLdb
creating build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\__init__.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\CLIENT.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\CR.py -> build\lib.win-amd64-3.6\MySQLdb\constants

copying MySQLdb\constants\ER.py -> build\lib.win-amd64-3.6\MySQLdb\constants

copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\FLAG.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants
EFRESH.py -> build\lib.win-amd64-3.6\MySQLdb\constants

运行build_ext

1
2
3
4
5
6
7
8
9
10
building '_mysql' extension
creating build\temp.win-amd64-3.6
creating build\temp.win-amd64-3.6
elease
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.14.26428\bin\HostX86\x64\cl.exe /c/nologo/Ox /W3 /GL /DNDEBUG /MD -Dversion_info=(1,3,13,'final',0) -D__version__=1.3.13"-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include" -Ic:\users\amccommon349\appdata\local\programs\python\python36\include -Ic:\users\amccommon349\appdata\local\programs\python\python36\include"-IC:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.14.26428\include""-IC:\Program Files (x86)\Windows Kits
ETFXSDK\4.6.1\include\um"
"-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\ucrt""-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\shared""-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\um""-IC:\ProgramFiles (x86)\Windows Kits\10\include\10.0.17134.0\winrt""-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\cppwinrt" /Tc_mysql.c /Fobuild\temp.win-amd64-3.6
elease\_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\\x64\\cl.exe' failed with exit status 2

我确保已拥有Visual Studio构建工具所需的所有文件,下载了mysql-python连接器,并更新了pip和设置工具。 我是一个完整的初学者,非常感谢您提供有关如何解决此错误的任何意见。


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

只需下载最适合您的mysqlclient.whl文件即可。我想你的情况是

mysqlclient?1.3.13?cp36?cp36m?win_amd64.whl

并运行

1
pip install"path to the downloaded .whl file"


尝试在64位环境中为python32安装mysqlclient时发生此错误。
卸载python,然后重新安装64位版本。然后pip install mysqlclient将无错误运行。


很有可能,这是我见过的最愚蠢的错误之一。
我拥有Python 3.7.3 32bit和最新的pip3,并且正在为我的Python安装轮子。...我偶然发现了这个STUPID错误。...
可能我的情况有些不同,但是您可以通过仔细查看错误来解决。....最初似乎缺少某些东西,您开始责怪您,Windows,32/64位,并且列表还在不断增加。
退后一步...只是退后一步,只需阅读讨厌的红色错误消息...即可。请认真阅读。
就我而言

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
ERROR: Command errored out with exit status 1:
     command: 'c:\users\myUserName\appdata\local\programs\python\python37-32\python.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:\Users\MASTER~1\AppData\Local\Temp\pip-record-z1mvci5v\install-record.txt' --single-version-externally-managed --compile
         cwd: C:\Users\MASTER~1\AppData\Local\Temp\pip-install-z7x81g2q\mysqlclient\
    Complete output (30 lines):
    running install
    running build
    running build_py
    creating build
    creating build\lib.win32-3.7
    creating build\lib.win32-3.7\MySQLdb
    copying MySQLdb\__init__.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\_exceptions.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\compat.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\connections.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\converters.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\cursors.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb
elease.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\times.py -> build\lib.win32-3.7\MySQLdb
    creating build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\__init__.py -> build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\CLIENT.py -> build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\CR.py -> build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\ER.py -> build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\FLAG.py -> build\lib.win32-3.7\MySQLdb\constants
    running build_ext
    building 'MySQLdb._mysql' extension
    creating build\temp.win32-3.7
    creating build\temp.win32-3.7
elease
    creating build\temp.win32-3.7
elease\MySQLdb
    C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.21.27702\bin\HostX86\x86\cl.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)\MySQL\MySQL Connector C 6.1\include\mariadb" -Ic:\users\MyUserName\appdata\local\programs\python\python37-32\include -Ic:\users\MyUserName\appdata\local\programs\python\python37-32\include"-IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.21.27702\include""-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt""-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared""-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um""-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt""-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt" /TcMySQLdb/_mysql.c /Fobuild\temp.win32-3.7
elease\MySQLdb/_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\\x86\\cl.exe' failed with exit status 2
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\users\MyUserName\appdata\local\programs\python\python37-32\python.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:\Users\MASTER~1\AppData\Local\Temp\pip-record-z1mvci5v\install-record.txt' --single-version-externally-managed --compile Check the logs for full command output.

您读得好吗?...我假设您具备一切...生成工具,MySQL Connector C 6.1 ...甚至将其移至Program Files(x86)...所以出了什么问题... ?? ...
现在仔细看看

1
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.21.27702\bin\HostX86\x86\cl.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)\MySQL\MySQL Connector C 6.1\include\mariadb" -

我敢肯定你看到了它...还没有?....让我为你加粗

1
"-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include\mariadb" -

玛丽亚德
好吧,这不是最愚蠢的...安装程序会查找mariadb includes和更高版本的libs
只需访问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文件夹进行相同的钻取
所以你应该有

1
2
3
C:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include\mariadb  

C:\Program Files (x86)\MySQL\MySQL Connector C 6.1\lib\mariadb

现在点击pip3 install mysqlclient
并享受无without安装...的结束

1
Successfully installed mysqlclient-1.4.2.post1

这是Windows 10上python的64位版本的问题。下面为我修复了该问题。

  • 为Windows安装32位版本的python(当前为3.7.1版)
  • 安装Visual Studio构建工具

    Downloads | IDE, Code, & Team Foundation Server | Visual Studio


    对于C ++

  • 从https://downloads.mysql.com/archives/c-c/安装32位mysql连接器版本6.1.11
  • 之后,我可以用pip install mysqlclint安装mysqlclient。

    希望有人会提出一个不需要降级到32位的更好的解决方案,因为这不是一个好的解决方案,它可以工作。我找到了解决mysql问题的方法,但是在尝试安装频道时又遇到了问题。似乎python 64位正在寻找32位库,而不是Windows上的64位库。到目前为止,该解决方案已解决了Windows上所有的python构建问题。


    我遇到了这个问题(错误完全相同),并尝试了上述所有解决方案,但它们都不起作用(至少对我而言),实际上,我要为解决这个问题而努力,直到我找到一个非常奇怪的解决方案为止,简单而愚蠢的方式! 。

    我执行了以下步骤,以便解决问题并再次过上幸福的生活。

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

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

    请注意,如果MySQL文件夹中不存在MySQL文件夹(对于我来说不存在),则可能必须创建该文件夹

    如此简单,它对我有用,似乎对于某些(或全部)64位Windows,pip或更可能是mysqlclient安装脚本,它仅在Program files (x86)文件夹中搜索某些MySQL文件(例如" mysql.h" ),并且不会搜索Program files,并且由于在Program files (x86)中未找到任何内容,导致错误非常愚蠢!!!是不是


    上面的解决方案都不适合我。显然我不得不将我的Python从3.7.x降级到3.6.4,这为我解决了这个问题。 python=3.6.4的下载链接。

    我建议为此创建一个新的虚拟环境,而不要卸载主python。在此处找到有关如何创建venv的大量文档。


    我在Django项目中尝试相同的方法。
    我尝试使用:
    pip install mysql-python
    这给了我以下错误:
    'mysql.h': No such file or directory
    摆弄reuqirements.txt之后,这又给了我另一个错误

    1
    2
    3
    4
    5
    6
    7
    8
    9
      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


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

    当我尝试安装MYSQL Client时

    1
    pip install mysqlclient

    第一个错误

    MySQLdb/_mysql.c(29): fatal error C1083: Cannot open include file: 'mysql.h': No such file or directory

    并且还尝试安装Django Channels

    1
    pip install -U channels

    第二次错误

    error: Microsoft Visual C++ 14.0 is required. Get it with"Microsoft Visual C++ Build Tools": https://visualstudio.microsoft.com/downloads/

    下载构建工具:
    Microsoft构建工具

    堆栈溢出 :
    如何安装/选择所需的构建工具

    已安装的构建工具。 (快乐编码)

    @Ralph Ritoch解决方案对我以及其他收到Mysql Client错误的人都有效。

    但是我也安装了Django Channels,所以我按照下面提到的步骤进行操作

    跟着这些步骤

  • Windows 10 64位
  • Python 64位3.7.3
  • mysql-connector-c-6.1.11-winx64
  • 构建工具
  • 我还安装了Django Channels 2.2.0,没有收到任何错误。

    Successfully installed mysqlclient

    (注意)

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

    Copy c:\Program Files\MySQL\MySQL Connector C 6.0.2\ directory to c:\Program Files (x86)\MySQL\MySQL Connector C 6.1\

    因此,我没有更改MySQL Connector的目录。 (您也可以检查此内容)

    也许为您工作!

    其他Stack解决方案更改目录

    可能的原因

    为什么我们会出错。

  • Python 32/64位版本
  • MySQL Connector 32/64位版本
  • 目录问题
  • 视窗32/64位版本
  • 未安装生成工具(如果需要获取Microsoft Visual C ++ 14.0,则为)
  • 感谢所有发布解决方案的人。


    在命令行中,只需键入:

    1
    python --

    代替:

    1
    python --version

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