python - VSCode,为什么我在尝试将 mysqlclient 安装到 django 项目时出现错误

标签 python mysql windows visual-studio-code

我正在尝试将 mysql 集成到 django 项目,但是当我尝试 pip install mysqlclient VSCode 抛出此错误:

Collecting mysqlclient
  Using cached https://files.pythonhosted.org/packages/4d/38/c5f8bac9c50f3042c8f05615f84206f77f03db79781db841898fde1bb284/mysqlclient-1.4.4.tar.gz
Installing collected packages: mysqlclient
  Running setup.py install for mysqlclient ... error
    ERROR: Command errored out with exit status 1:
     command: 'c:\users\popcorn\appdata\local\programs\python\python37-32\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\popcorn\\AppData\\Local\\Temp\\pip-install-yefz5w6i\\mysqlclient\\setup.py'"'"'; __file__='"'"'C:\\Users\\popcorn\\AppData\\Local\\Temp\\pip-install-yefz5w6i\\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\popcorn\AppData\Local\Temp\pip-record-f55ih7zv\install-record.txt' --single-version-externally-managed --compile
         cwd: C:\Users\popcorn\AppData\Local\Temp\pip-install-yefz5w6i\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\release.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\Release
    creating build\temp.win32-3.7\Release\MySQLdb
    C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.22.27905\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MT -Dversion_info=(1,4,4,'final',0) -D__version__=1.4.4 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include\mariadb" -Ic:\users\popcorn\appdata\local\programs\python\python37-32\include -Ic:\users\popcorn\appdata\local\programs\python\python37-32\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.22.27905\include" /TcMySQLdb/_mysql.c /Fobuild\temp.win32-3.7\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.22.27905\\bin\\HostX86\\x86\\cl.exe' failed with exit status 2
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\users\popcorn\appdata\local\programs\python\python37-32\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\popcorn\\AppData\\Local\\Temp\\pip-install-yefz5w6i\\mysqlclient\\setup.py'"'"'; __file__='"'"'C:\\Users\\popcorn\\AppData\\Local\\Temp\\pip-install-yefz5w6i\\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\popcorn\AppData\Local\Temp\pip-record-f55ih7zv\install-record.txt' --single-version-externally-managed --compile Check the 
logs for full command output.

有人知道我该如何解决这个问题吗?我已经安装了 Microsoft Visual C++ 包版本 14.22。

最佳答案

latest release of mysqlclient有适用于 Windows 的轮子,但它们适用于 64 位。如果您安装的是 64 位 Windows,我将通过安装 64 位版本的 Python 来解决此问题。否则,这似乎是 sdist 中的一个错误,其中头文件被意外遗漏。

关于python - VSCode,为什么我在尝试将 mysqlclient 安装到 django 项目时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58056911/

相关文章:

python xpath : single quotationmarks and double quotationmarks

python - [u "'0' 值的日期格式无效。它必须采用 YYYY-MM-DD 格式。"]

python - 从 python 子进程中的 fd#3 读取

mysql - 解释以前回答的帖子 : Finding Median in MySQL 的解决方案

php - 从 mySQL 切换到 noSQL - 词典网站

c++ - 多线程单读单写fifo队列

python - 最新 python 更新后读取长路径(>256 个字符)的文件时出现问题

python - 如何删除字符串中第一次出现的字符之后的每次出现

MySQl,为什么会使用完全错误的索引?

c++ - MinGW-w64 OpenGL 链接器错误