python - 在 Django 中安装 MySQL 客户端显示错误

标签 python mysql django

您好,我正在尝试在 Django 中安装 Mysqlclient,我收到了这条消息

collecting mysqlclient
  Using cached https://files.pythonhosted.org/packages/f4/f1/3bb6f64ca7a429729413e6556b7ba5976df06019a5245a43d36032f1061e/mysqlclient-1.4.2.post1.tar.gz
Building wheels for collected packages: mysqlclient
  Building wheel for mysqlclient (setup.py) ... error
  ERROR: Complete output from command 'c:\users\usermo~1\virtua~1\tmsv2_~2\scripts\python.exe' -u -c 'import setuptools, tokenize;__file__='"'"'C:\\Users\\userMO~1\\AppData\\Local\\Temp\\pip-install-vzfx29bg\\mysqlclient\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\userMO~1\AppData\Local\Temp\pip-wheel-rd_6y67h' --python-tag cp37:
  ERROR: running bdist_wheel
  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\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -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\user moe\appdata\local\programs\python\python37-32\include" "-Ic:\users\user moe\appdata\local\programs\python\python37-32\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-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\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\\2017\\BuildTools\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX86\\x86\\cl.exe' failed with exit status 2
  ----------------------------------------
  ERROR: Failed building wheel for mysqlclient
  Running setup.py clean for mysqlclient
Failed to build mysqlclient
Installing collected packages: mysqlclient
  Running setup.py install for mysqlclient ... error
    ERROR: Complete output from command 'c:\users\usermo~1\virtua~1\tmsv2_~2\scripts\python.exe' -u -c 'import setuptools, tokenize;__file__='"'"'C:\\Users\\userMO~1\\AppData\\Local\\Temp\\pip-install-vzfx29bg\\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\userMO~1\AppData\Local\Temp\pip-record-ea_7lykd\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\usermo~1\virtua~1\tmsv2_~2\include\site\python3.7\mysqlclient':
    ERROR: 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\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -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\user moe\appdata\local\programs\python\python37-32\include" "-Ic:\users\user moe\appdata\local\programs\python\python37-32\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-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\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\\2017\\BuildTools\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX86\\x86\\cl.exe' failed with exit status 2
    ----------------------------------------
ERROR: Command "'c:\users\usermo~1\virtua~1\tmsv2_~2\scripts\python.exe' -u -c 'import setuptools, tokenize;__file__='"'"'C:\\Users\\userMO~1\\AppData\\Local\\Temp\\pip-install-vzfx29bg\\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\userMO~1\AppData\Local\Temp\pip-record-ea_7lykd\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\usermo~1\virtua~1\tmsv2_~2\include\site\python3.7\mysqlclient'" failed with error code 1 in C:\Users\userMO~1\AppData\Local\Temp\pip-install-vzfx29bg\mysqlclient\

我已经尝试了几种方法

  • pip install opencv-contrib-python(可以安装不行)
  • pip install mysqlclient==1.3.12(显示同样的错误)
  • 我从 Wheel Link 安装 mycsqlclient| (显示此错误 mysqlclient-1.4.2-cp38-cp38m-win_amd64.whl is not a supported wheel on this platform.)

我的python版本是:3.7.3

(我来自桌面环境,当我阅读 Django 时,它说“快得离谱”,但现在 MySQL 连接问题已经花了 4 天)。

最佳答案

您下载了错误的轮子。错误消息说您尝试安装适用于 Python 3.8 的 mysqlclient-1.4.2-cp38-cp38m-win_amd64.whl

由于您使用的是 Python 3.7,因此您应该使用 mysqlclient‑1.4.2‑cp37‑cp37m‑win32.whlmysqlclient‑1.4.2‑cp37‑cp37m‑win_amd64。 whl 取决于您安装的是 32 位还是 64 位 Python。

关于python - 在 Django 中安装 MySQL 客户端显示错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56643488/

相关文章:

MySQL递增值

python - Django 部署 : configuring correct python to be used by apache/mod_wsgi

php - 在 MySQL 中执行查询的性能。也许正在使用缓存?

python - 正则表达式可在更多条件下匹配版权声明中的公司名称

python - Docker,错误 :zygote_host_impl_linux. cc(89)] 不支持在没有 --no-sandbox 的情况下以 root 身份运行

Mysql NOT IN 子句查询不返回我想要的

mysql - Configuration failed because libmysqlclient was not found.解决方法是什么?

python - Django原始id字段查找有错误的链接

嵌套字典的元组的 Python 列表

python - 深度缩放 Weierstrass 函数等函数 - 用于超高精度 float 学的工作示例或库或起始代码?