无法安装mysqlclient

问题描述 投票:0回答:3
pip install mysqlclient
Collecting mysqlclient
  Using cached mysqlclient-2.1.1.tar.gz (88 kB)
  Preparing metadata (setup.py) .. done
Building wheels for collected packages: mysqlclient
  Building wheel for mysqlclient (setup.py) .. error
  ERROR: Command errored out with exit status 1:
   command: 'c:\users\hp\appdata\local\programs\python\python36\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\HP\\AppD
ata\\Local\\Temp\\pip-install-mmb7531p\\mysqlclient_a141c7c0a933439fbe19807e877c7cc2\\setup.py'"'"'; __file__='"'"'C:\\Users\\HP\\AppData\\Local\\Temp\\pip-install
-mmb7531p\\mysqlclient_a141c7c0a933439fbe19807e877c7cc2\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.St
ringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'
))' bdist_wheel -d 'C:\Users\HP\AppData\Local\Temp\pip-wheel-44gqcvbi'
       cwd: C:\Users\HP\AppData\Local\Temp\pip-install-mmb7531p\mysqlclient_a141c7c0a933439fbe19807e877c7cc2\
  Complete output (25 lines):
  c:\users\hp\appdata\local\programs\python\python36\lib\distutils\dist.py:261: UserWarning: Unknown distribution option: 'long_description_content_type'
    warnings.warn(msg)
  running bdist_wheel
  running build
  running build_py
  creating build
  creating 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\_exceptions.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\release.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
  running build_ext
  building 'MySQLdb._mysql' extension
  error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools
  ----------------------------------------
  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: Command errored out with exit status 1:
     command: 'c:\users\hp\appdata\local\programs\python\python36\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\HP\\Ap
pData\\Local\\Temp\\pip-install-mmb7531p\\mysqlclient_a141c7c0a933439fbe19807e877c7cc2\\setup.py'"'"'; __file__='"'"'C:\\Users\\HP\\AppData\\Local\\Temp\\pip-insta
ll-mmb7531p\\mysqlclient_a141c7c0a933439fbe19807e877c7cc2\\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\HP\AppData\Local\Temp\pip-record-ylfwp41x\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\
users\hp\appdata\local\programs\python\python36\Include\mysqlclient'
         cwd: C:\Users\HP\AppData\Local\Temp\pip-install-mmb7531p\mysqlclient_a141c7c0a933439fbe19807e877c7cc2\
    Complete output (25 lines):
    c:\users\hp\appdata\local\programs\python\python36\lib\distutils\dist.py:261: UserWarning: Unknown distribution option: 'long_description_content_type'        
      warnings.warn(msg)
    running install
    running build
    running build_py
    creating build
    creating 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\_exceptions.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\release.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
    running build_ext
    building 'MySQLdb._mysql' extension
    error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools        
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\users\hp\appdata\local\programs\python\python36\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys
.argv[0] = '"'"'C:\\Users\\HP\\AppData\\Local\\Temp\\pip-install-mmb7531p\\mysqlclient_a141c7c0a933439fbe19807e877c7cc2\\setup.py'"'"'; __file__='"'"'C:\\Users\\HP
\\AppData\\Local\\Temp\\pip-install-mmb7531p\\mysqlclient_a141c7c0a933439fbe19807e877c7cc2\\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(com
pile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\HP\AppData\Local\Temp\pip-record-ylfwp41x\install-record.txt' --single-version-externally-managed
 --compile --install-headers 'c:\users\hp\appdata\local\programs\python\python36\Include\mysqlclient' Check the logs for full command output.

我正在尝试在 Pycharm 中安装 mysqlclient。但我不能,它向我显示这些错误。为 mysqlclient 构建轮子时出现错误。 Django 版本是 3.2.18。点子版本是 21.3.1。这个错误是不是pip和mysqlclient的版本不匹配导致的? ..................................................... ..................................................... …………

python mysql django pycharm
3个回答
0
投票

为什么不使用 MSI 安装文件来安装它。

pip
没关系,我会检查是什么问题,但暂时去这里安装:https://dev.mysql.com/downloads/installer/

MySQL 客户端在您的机器上安装完整套件(包括 CLI)。你说 PyCharm,它会使用 CLI。所以只需安装完整的套件设置。

看,我刚刚做了这个,

PS C:\Users\Archisman> pip install mysqlclient
Collecting mysqlclient
  Downloading mysqlclient-2.1.1-cp310-cp310-win_amd64.whl (178 kB)
     ---------------------------------------- 178.4/178.4 kB 10.5 MB/s eta 0:00:00
Installing collected packages: mysqlclient
Successfully installed mysqlclient-2.1.1

[notice] A new release of pip available: 22.3.1 -> 23.0.1
[notice] To update, run: C:\Users\Archisman\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\python.exe -m pip install --upgrade pip
PS C:\Users\Archisman>

我已经通过安装文件安装了 MySQL 并且无处不在。所以,只需下载安装程序并安装它。

pip install mysqlclient
可能会留下一些要安装的软件包,这会导致错误。

另外不要忘记 MySQL 需要 MS Visual Studio Build Tools。所以,最好运行安装程序。

更新 在你的 Shell 中找到这个:

error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools

正是我猜到的。


0
投票

如错误消息所示,问题可能出在“Microsoft Visual C++ 构建工具”上。因此,请尝试安装该依赖项。


0
投票

我更新了我的python 3.8版本,问题解决了。

© www.soinside.com 2019 - 2024. All rights reserved.