无法安装mysqlcient:无法打开包含文件:“ mysql.h”

时间:2020-01-11 19:04:35

标签: python django pip

每次我运行命令(pip install mysqlclient)时,都会出现此错误:

  ERROR: Command errored out with exit status 1:

     command: 'c:\users\nicko\envs\py1\scripts\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\nicko\\AppData\\Local\\Temp\\pip-install-av2k0hkf\\mysqlclient\\setup.py'"'"'; __file__='"'"'C:\\Users\\nicko\\AppData\\Local\\Temp\\pip-install-av2k0hkf\\mysqlclient\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\nicko\AppData\Local\Temp\pip-record-dbm3hthv\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\nicko\envs\py1\include\site\python3.8\mysqlclient'
         cwd: C:\Users\nicko\AppData\Local\Temp\pip-install-av2k0hkf\mysqlclient\
    Complete output (30 lines):
    running install
    running build
    running build_py
    creating build
    creating build\lib.win32-3.8
    creating build\lib.win32-3.8\MySQLdb
    copying MySQLdb\__init__.py -> build\lib.win32-3.8\MySQLdb
    copying MySQLdb\_exceptions.py -> build\lib.win32-3.8\MySQLdb
    copying MySQLdb\compat.py -> build\lib.win32-3.8\MySQLdb
    copying MySQLdb\connections.py -> build\lib.win32-3.8\MySQLdb
    copying MySQLdb\converters.py -> build\lib.win32-3.8\MySQLdb
    copying MySQLdb\cursors.py -> build\lib.win32-3.8\MySQLdb
    copying MySQLdb\release.py -> build\lib.win32-3.8\MySQLdb
    copying MySQLdb\times.py -> build\lib.win32-3.8\MySQLdb
    creating build\lib.win32-3.8\MySQLdb\constants
    copying MySQLdb\constants\__init__.py -> build\lib.win32-3.8\MySQLdb\constants
    copying MySQLdb\constants\CLIENT.py -> build\lib.win32-3.8\MySQLdb\constants
    copying MySQLdb\constants\CR.py -> build\lib.win32-3.8\MySQLdb\constants
    copying MySQLdb\constants\ER.py -> build\lib.win32-3.8\MySQLdb\constants
    copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win32-3.8\MySQLdb\constants
    copying MySQLdb\constants\FLAG.py -> build\lib.win32-3.8\MySQLdb\constants
    running build_ext
    building 'MySQLdb._mysql' extension
    creating build\temp.win32-3.8
    creating build\temp.win32-3.8\Release
    creating build\temp.win32-3.8\Release\MySQLdb
    C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.24.28314\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Dversion_info=(1,4,6,'final',0) -D__version__=1.4.6 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include\mariadb" "-Id:\a\jan10python\new folder\include" "-Id:\a\jan10python\new folder\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.24.28314\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\cppwinrt" /TcMySQLdb/_mysql.c /Fobuild\temp.win32-3.8\Release\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.24.28314\\bin\\HostX86\\x86\\cl.exe' failed with exit status 2
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\users\nicko\envs\py1\scripts\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\nicko\\AppData\\Local\\Temp\\pip-install-av2k0hkf\\mysqlclient\\setup.py'"'"'; __file__='"'"'C:\\Users\\nicko\\AppData\\Local\\Temp\\pip-install-av2k0hkf\\mysqlclient\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\nicko\AppData\Local\Temp\pip-record-dbm3hthv\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\nicko\envs\py1\include\site\python3.8\mysqlclient' Check the logs for full command output.

上面的要点可能是fatal error C1083: Cannot open include file: 'mysql.h'行,但我不知道该怎么办。

我尝试了许多其他“解决方案”。有些太混乱了。其他人根本不工作(mysql-python install error: Cannot open include file 'config-win.h'“Cannot open include file: 'config-win.h': No such file or directory” while installing mysql-python)。谁有想法?我应该尝试安装任何东西,然后在哪里安装?如果您有任何可以共享的链接,我将接受其中任何一个。

额外:我可以说我很愚蠢,所以如果您确实对我提出疑问,您将不得不解释几乎所有内容,否则我将继续提问,您可能会很烦:D谢谢

1 个答案:

答案 0 :(得分:0)

您缺少应通过mysql client connector installer安装的mysql标头。

更简单的方法是通过滚轮安装它,如果您的python是x64版本,它应该自动使用official wheel,但是您可以下载并安装unofficial compiled wheel(您应该选择下载版本) python(3.8 x86?)并使用安装)

pip install some-package.whl