首页 > 解决方案 > 无法在 python 中安装“mysqlclient”包

问题描述

我正在尝试在 python 中安装 mysqlclient 包,但出现以下错误

(venv) C:\Users\Grv\PycharmProjects\Employee>pip install mysqlclient
Collecting mysqlclient
  Using cached mysqlclient-2.0.3.tar.gz (88 kB)
Using legacy 'setup.py install' for mysqlclient, since package 'wheel' is not installed.
Installing collected packages: mysqlclient
    Running setup.py install for mysqlclient ... error
    ERROR: Command errored out with exit status 1:
     command: 'c:\users\grv\pycharmprojects\employee\venv\scripts\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Grv\\AppData\\Local\\Temp\\pip
-install-i_sgg0o6\\mysqlclient_263511bdd06944be9431012ebadf8f3b\\setup.py'"'"'; __file__='"'"'C:\\Users\\Grv\\AppData\\Local\\Temp\\pip-install-i_sgg0o6\\mysqlclient_263511bdd06944be94310
12ebadf8f3b\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.rea
d().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\Grv\AppData\Local\Temp\pip-record-rk5je4if\install-record.txt
' --single-version-externally-managed --compile --install-headers 'c:\users\grv\pycharmprojects\employee\venv\include\site\python3.8\mysqlclient'
         cwd: C:\Users\Grv\AppData\Local\Temp\pip-install-i_sgg0o6\mysqlclient_263511bdd06944be9431012ebadf8f3b\
    Complete output (29 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\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.28.29910\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Dversion_info=(2,0,3,'final',0) -D
__version__=2.0.3 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include\mariadb" -Ic:\users\grv\pycharmprojects\employee\venv\include -IC:\Users\Grv\AppData\Local\Programs\Python\
Python38-32\include -IC:\Users\Grv\AppData\Local\Programs\Python\Python38-32\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\include" "
-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\includ
e\10.0.19041.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\cppwinrt" /TcMySQLdb/_mysql.c /Fobu
ild\temp.win32-3.8\Release\MySQLdb/_mysql.obj
    _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.28.29910\\bin\\HostX86\\x86\\cl.exe' failed with exit status 2
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\users\grv\pycharmprojects\employee\venv\scripts\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\User
s\\Grv\\AppData\\Local\\Temp\\pip-install-i_sgg0o6\\mysqlclient_263511bdd06944be9431012ebadf8f3b\\setup.py'"'"'; __file__='"'"'C:\\Users\\Grv\\AppData\\Local\\Temp\\pip-install-i_sgg0o6\\
mysqlclient_263511bdd06944be9431012ebadf8f3b\\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 'C:\Users\Grv\AppData\Local\Temp\pip-r
ecord-rk5je4if\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\grv\pycharmprojects\employee\venv\include\site\python3.8\mysqlclient' Check th
e logs for full command output.

标签: pythonmysqldjango

解决方案


推荐阅读