Python 2.7 中安裝 MySQL-python 提示 ERROR: Command errored out with exit status 1
在Python 2.7 中安裝 MySQL-python 時提示說 C++ 有問題,然后我就找到對應的 C++ 安裝包,安裝好后再次提醒錯誤 ERROR: Command errored out with exit status 1等等。
首先,我在網上找到了對應的 C++ 安裝包。然后進行了安裝。下載地址 提取碼:xoz2
安裝完以后,重啟電腦,再次出現錯誤,提示:ERROR: Command errored out with exit status 1
。具體錯誤信息如下:
......
creating build\temp.win32-2.7
creating build\temp.win32-2.7\Release
C:\Users\EDZ\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\cl.exe /c /nologo /Ox /MD
/W3 /GS- /DNDEBUG -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 "-IC:\Program Files (x86)\MySQL\MySQL Conne
ctor C 6.0.2\include" -Ic:\python27\include -Ic:\python27\PC /Tc_mysql.c /Fobuild\temp.win32-2.7\Release\_mysql.obj
/Zl
_mysql.c
_mysql.c(42) : fatal error C1083: Cannot open include file: 'config-win.h': No such file or directory
error: command 'C:\\Users\\EDZ\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bi
n\\cl.exe' failed with exit status 2
----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\python27\python.exe' -u -c 'import sys, setuptools, tokenize; s
_mysql.c
_mysql.c(42) : fatal error C1083: Cannot open include file: 'config-win.h': No such file or directory
error: command 'C:\\Users\\EDZ\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\B
in\\cl.exe' failed with exit status 2
----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\python27\python.exe' -u -c 'import sys, setuptools, tokenize; s
ys.argv[0] = '"'"'c:\\users\\edz\\appdata\\local\\temp\\pip-install-30w9j7\\mysql-python\\setup.py'"'"'; __file__=
'"'"'c:\\users\\edz\\appdata\\local\\temp\\pip-install-30w9j7\\mysql-python\\setup.py'"'"';f=getattr(tokenize, '"'
"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __fi
le__, '"'"'exec'"'"'))' install --record 'c:\users\edz\appdata\local\temp\pip-record-ms4ymt\install-record.txt' --
single-version-externally-managed --compile --install-headers 'c:\python27\Include\MySQL-python' Check the logs fo
r full command output.
這個問題大概分三步解決:
1. 下載 MySQL-python 或者是 Mysqlclient的.whl 包,注意對應自己安裝的python版本,如何使32 bit就下載對應32位的版本;
Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:22:17) [MSC v.1500 32 bit (Intel)] on win32
如上,我的是win32的,我選如下:
MySQL-python: a Python database API 2.0 interface for the MySQL database
Consider mysqlclient, a Python 3 compatible fork of MySQL-python.
MySQL_python‑1.2.5‑cp27‑none‑win32.whl
下載以后進行安裝,如下:
pip install path\MySQL_python-1.2.5-cp27-none-win32.whl
安裝完成以后,使用pip list
進行查看,MySQL-python 安裝成功。