解決windows64位系統上安裝mysql-python報錯

解決windows64位系統上安裝mysql-python報錯

 版權聲明:本文爲博主原創文章,未經博主容許不得轉載。 https://blog.csdn.net/yu12377/article/details/79525470

1、 背景

python項目中須要操做mysql,因而運行:python

pip install MySQL-python

報一連串的錯誤,前面的錯誤根據提示都好解決,但被下面的錯誤一直卡住,好一翻折騰才解決,因此在此記錄以備忘。mysql

Cannot open include file: ‘config-win.h’: No such file or directory」 while installing mysql-pythonsql

2、 安裝

1. 安裝64位版本的python

https://www.python.org/ftp/python/2.7.14/python-2.7.14.amd64.msiwindows

2. 安裝VCForPython

去微軟官網下載 
沒有安裝時會報以下錯誤:bash

根據錯誤提示,訪問:http://aka.ms/vcpython27 C:\Users\admin\Desktop>pip install mysql-python Collecting mysql-python Using cached MySQL-python-1.2.5.zip Installing collected packages: mysql-python Running setup.py install for mysql-python ... error Complete output from command c:\python27\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\admin\\appdata\\local\\temp\\pip-build-srpbqq\\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\admin\appdata\local\temp\pip-6qgvvl-record\install-record.txt --single-version-externally-managed --compile: running install running build running build_py creating build creating build\lib.win-amd64-2.7 copying _mysql_exceptions.py -> build\lib.win-amd64-2.7 creating build\lib.win-amd64-2.7\MySQLdb copying MySQLdb\__init__.py -> build\lib.win-amd64-2.7\MySQLdb copying MySQLdb\converters.py -> build\lib.win-amd64-2.7\MySQLdb copying MySQLdb\connections.py -> build\lib.win-amd64-2.7\MySQLdb copying MySQLdb\cursors.py -> build\lib.win-amd64-2.7\MySQLdb copying MySQLdb\release.py -> build\lib.win-amd64-2.7\MySQLdb copying MySQLdb\times.py -> build\lib.win-amd64-2.7\MySQLdb creating build\lib.win-amd64-2.7\MySQLdb\constants copying MySQLdb\constants\__init__.py -> build\lib.win-amd64-2.7\MySQLdb\constants copying MySQLdb\constants\CR.py -> build\lib.win-amd64-2.7\MySQLdb\constants copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win-amd64-2.7\MySQLdb\constants copying MySQLdb\constants\ER.py -> build\lib.win-amd64-2.7\MySQLdb\constants copying MySQLdb\constants\FLAG.py -> build\lib.win-amd64-2.7\MySQLdb\constants copying MySQLdb\constants\REFRESH.py -> build\lib.win-amd64-2.7\MySQLdb\constants copying MySQLdb\constants\CLIENT.py -> build\lib.win-amd64-2.7\MySQLdb\constants running build_ext building '_mysql' extension error: Microsoft Visual C++ 9.0 is required. Get it from http://aka.ms/vcpython27 ---------------------------------------- Command "c:\python27\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\admin\\appdata\\local\\temp\\pip-build-srpbqq\\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\admin\appdata\local\temp\pip-6qgvvl-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in c:\users\admin\appdata\local\temp\pip-build-srpbqq\mysql-python\ C:\Users\admin\Desktop>

下載相應版本的VCForPython安裝,再次安裝mysql-pythonmarkdown

3. 安裝mysql-connector-python-2.1.7-py2.7-windows-x86-64bit.msi

https://cdn.mysql.com//Downloads/Connector-Python/mysql-connector-python-2.1.7-py2.7-windows-x86-64bit.msiapp

4. 安裝mysql-connector-c-6.0.2-winx64.msi

https://cdn.mysql.com//Downloads/Connector-C/mysql-connector-c-6.0.2-winx64.msi 
沒有安裝【mysql-connector-python】與【mysql-connector-c-6.0.2】時,會報以下錯誤:ui

C:\Users\admin\Desktop>pip install mysql-python Collecting mysql-python Using cached MySQL-python-1.2.5.zip Installing collected packages: mysql-python Running setup.py install for mysql-python ... error Complete output from command c:\python27\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\admin\\appdata\\local\\temp\\pip-build-r8dkiw\\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\admin\appdata\local\temp\pip-srrfzx-record\install-record.txt --single-version-externally-managed --compile: running install running build running build_py creating build creating build\lib.win-amd64-2.7 copying _mysql_exceptions.py -> build\lib.win-amd64-2.7 creating build\lib.win-amd64-2.7\MySQLdb copying MySQLdb\__init__.py -> build\lib.win-amd64-2.7\MySQLdb copying MySQLdb\converters.py -> build\lib.win-amd64-2.7\MySQLdb copying MySQLdb\connections.py -> build\lib.win-amd64-2.7\MySQLdb copying MySQLdb\cursors.py -> build\lib.win-amd64-2.7\MySQLdb copying MySQLdb\release.py -> build\lib.win-amd64-2.7\MySQLdb copying MySQLdb\times.py -> build\lib.win-amd64-2.7\MySQLdb creating build\lib.win-amd64-2.7\MySQLdb\constants copying MySQLdb\constants\__init__.py -> build\lib.win-amd64-2.7\MySQLdb\constants copying MySQLdb\constants\CR.py -> build\lib.win-amd64-2.7\MySQLdb\constants copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win-amd64-2.7\MySQLdb\constants copying MySQLdb\constants\ER.py -> build\lib.win-amd64-2.7\MySQLdb\constants copying MySQLdb\constants\FLAG.py -> build\lib.win-amd64-2.7\MySQLdb\constants copying MySQLdb\constants\REFRESH.py -> build\lib.win-amd64-2.7\MySQLdb\constants copying MySQLdb\constants\CLIENT.py -> build\lib.win-amd64-2.7\MySQLdb\constants running build_ext building '_mysql' extension creating build\temp.win-amd64-2.7 creating build\temp.win-amd64-2.7\Release C:\Users\admin\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\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 Connector C 6.0.2\include" -Ic:\python27\include -Ic:\python27\PC /Tc_mysql.c /Fobuild\temp.win-amd64-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\\admin\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\amd64\\cl.exe' failed with exit status 2 ---------------------------------------- Command "c:\python27\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\admin\\appdata\\local\\temp\\pip-build-r8dkiw\\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\admin\appdata\local\temp\pip-srrfzx-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in c:\users\admin\appdata\local\temp\pip-build-r8dkiw\mysql-python\

5. MySQL-python-1.2.5.zip

https://pypi.python.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip#md5=654f75b302db6ed8dc5a898c625e030c 
注意:沒有安裝【mysql-connector-python】與【mysql-connector-c-6.0.2】時:此步驟會一直報錯: 
> Cannot open include file: ‘config-win.h’: No such file or directory」 while installing mysql-pythonspa

注意:即便已經安裝了【mysql-connector-python】與【mysql-connector-c-6.0.2】,也可能會報上面的錯誤.net

緣由: pypi上提供的MySQL-python包依賴32位的mysql-connector-c-6.0.2包,由於咱們前面只安裝了64位的版本,全部一直找不到mysql-connector-c-6.0.2而報上面的錯誤

  • 解決方法一: 
    去mysql官網下載32位的mysql-connector-c-6.0.2,同時安裝32位版本與64位版本,再運行: 【親測,失敗,但此方法應該能夠,緣由本人沒有深究】
pip install mysql-python
  • 1

 


  • 解決方法二: 
    下載MySQL-python-1.2.5的源碼,解壓並修改文件【MySQL-python-1.2.5/site.cfg】,找到以下一行的路徑,將其修改爲以下第二行(修改引用版本,將32位指向64位),再運行python setup.py install安裝【親測經過】 (前提:安裝64位的mysql-connector-c-6.0.2,) 

 

connector = C:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2 
connector = C:\Program Files\MySQL\MySQL Connector C 6.0.2
# 源碼安裝 cd MySQL-python-1.2.5 python setup.py install
相關文章
相關標籤/搜索