【发布时间】:2020-11-16 15:57:43
【问题描述】:
我是 Django 的新手。我想为我的项目使用 Mysql 数据库。我正在为此安装 mysqlclient,但它显示以下错误。 我在用 --pip install mysql-python 安装mysqlclient的命令
Collecting mysql-python Using cached MySQL-python-1.2.5.zip (108 kB) Using legacy setup.py install for mysql-python, since package 'wheel' is not installed. Installing collected packages: mysql-python
Running setup.py install for mysql-python ... error
ERROR: Command errored out with exit status 1:
command: 'f:\xampp\htdocs\django\scripts\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\DELL\\AppData\\Local\\Temp\\pip-install-ti26jpbi\\mysql-python\\setup.py'"'"';
__file__='"'"'C:\\Users\\DELL\\AppData\\Local\\Temp\\pip-install-ti26jpbi\\mysql-python\\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\DELL\AppData\Local\Temp\pip-record-h90u4076\install-record.txt'
--single-version-externally-managed --compile --install-headers 'f:\xampp\htdocs\django\include\site\python3.8\mysql-python'
cwd: C:\Users\DELL\AppData\Local\Temp\pip-install-ti26jpbi\mysql-python\
Complete output (24 lines):
running install
running build
running build_py
creating build
creating build\lib.win32-3.8
copying _mysql_exceptions.py -> build\lib.win32-3.8
creating build\lib.win32-3.8\MySQLdb
copying MySQLdb\__init__.py -> build\lib.win32-3.8\MySQLdb
copying MySQLdb\converters.py -> build\lib.win32-3.8\MySQLdb
copying MySQLdb\connections.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\CR.py -> build\lib.win32-3.8\MySQLdb\constants
copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win32-3.8\MySQLdb\constants
copying MySQLdb\constants\ER.py -> build\lib.win32-3.8\MySQLdb\constants
copying MySQLdb\constants\FLAG.py -> build\lib.win32-3.8\MySQLdb\constants
copying MySQLdb\constants\REFRESH.py -> build\lib.win32-3.8\MySQLdb\constants
copying MySQLdb\constants\CLIENT.py -> build\lib.win32-3.8\MySQLdb\constants
running build_ext
building '_mysql' extension
error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": https://visualstudio.microsoft.com/downloads/
---------------------------------------- ERROR: Command errored out with exit status 1: 'f:\xampp\htdocs\django\scripts\python.exe' -u
-c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\DELL\\AppData\\Local\\Temp\\pip-install-ti26jpbi\\mysql-python\\setup.py'"'"';
__file__='"'"'C:\\Users\\DELL\\AppData\\Local\\Temp\\pip-install-ti26jpbi\\mysql-python\\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\DELL\AppData\Local\Temp\pip-record-h90u4076\install-record.txt'
--single-version-externally-managed --compile --install-headers 'f:\xampp\htdocs\django\include\site\python3.8\mysql-python' Check the logs for full command output.
我使用的是 Windows 10。 如果有人可以帮助我解决此错误,我将不胜感激。
【问题讨论】:
-
在这里使用我的答案stackoverflow.com/a/61293962/5193536
-
MySQL-python只支持Python 2。使用pip install mysqlclient安装mysqlclient。确保您安装了 64 位 Python - 这样它就会安装轮子。 -
我在使用 pip install mysqlclient 时遇到同样的错误。
-
mysqlclient可能会出现类似的错误,但不会相同,因此请改为显示该错误。正如我之前所说,最简单的解决方案是切换到 64 位 Python,然后您就不必构建mysqlclient。
标签: python mysql mysql-python