我试图安装mysqlclient
Python包( https://pypi.python.org/pypi/mysqlclient )到Windows 7上的虚拟Python 2.7环境(在本地PC上和Appveyor CI上)并且无法完成。
我正在用Win 7描述本地PC的问题,但是它在Appveyor上发生的方式基本相同。
当我开始时,在我的virtualenv包:
pip (9.0.1) setuptools (36.6.0) wheel (0.30.0)
pip install mysqlclient
最初说:
. . . running build_ext building '_mysql' extension error: Microsoft Visual C++ 9.0 is required. Get it from http://aka.ms/vcpython27
显然,Python 2.7需要VC9。 安装完成后, pip install mysqlclient
得到一点点进一步,但错过包含文件:
. . . building '_mysql' extension creating build\temp.win-amd64-2.7 creating build\temp.win-amd64-2.7\Release C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -Dversion_info=(1,3,12,'final',0) -D__version__=1.3.12 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include" -IC:\Python27\include -IC:\Users\Andi\virtualenvs\mysqlclient\PC /Tc_mysql.c /Fobuild\temp.win-amd64-2.7\Release\_mysql.obj /Zl _mysql.c _mysql.c(29) : fatal error C1083: Cannot open include file: 'mysql.h': No such file or directory error: command 'C:\\Program Files (x86)\\Common Files\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\amd64\\cl.exe' failed with exit status 2
为了得到头文件,我从https://downloads.mysql.com/archives/get/file/mysql-connector-c-6.1.10-winx64.msi安装了“MySQL Connector / C 6.1.10” 。 这当然只是第二个最新版本,但我需要从命令行安装在Appveyor上,并没有find如何以无人值守的方式下载最新版本。
另外,使用MSI安装程序将软件包安装在C:\Program Files\MySQL\MySQL Connector C 6.1
但是pip install中的构build步骤期望它位于C:\Program Files (x86)\MySQL\MySQL Connector C 6.1
,软链接它:
mklink /D "C:\Program Files (x86)\MySQL\MySQL Connector C 6.1" "C:\Program Files\MySQL\MySQL Connector C 6.1"
查看该版本的MySQL Connector / C中的文件时,只有lib / vs12和lib / vs14目录:
lib/vs12/mysqlclient.lib lib/vs14/mysqlclient.lib
正如所料, pip install mysqlclient
现在超越了编译,但链接失败:
. . . running build_ext building '_mysql' extension creating build\temp.win-amd64-2.7 creating build\temp.win-amd64-2.7\Release C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -Dversion_info=(1,3,12,'final',0) -D__version__=1.3.12 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include" -IC:\Python27\include -IC:\Users\Andi\virtualenvs\mysqlclient\PC /Tc_mysql.c /Fobuild\temp.win-amd64-2.7\Release\_mysql.obj /Zl _mysql.c _mysql.c(242) : .... several warnings ... C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\link.exe /DLL /nologo /INCREMENTAL:NO "/LIBPATH:C:\Program Files (x86)\MySQL\MySQL Connector C 6.1\lib\vs9" /LIBPATH:C:\Python27\Libs /LIBPATH:C:\Users\Andi\virtualenvs\mysqlclient\libs /LIBPATH:C:\Users\Andi\virtualenvs\mysqlclient\PCbuild\amd64 /LIBPATH:C:\Users\Andi\virtualenvs\mysqlclient\PC\VS9.0\amd64 kernel32.lib advapi32.lib wsock32.lib mysqlclient.lib /EXPORT:init_mysql build\temp.win-amd64-2.7\Release\_mysql.obj /OUT:build\lib.win-amd64-2.7\_mysql.pyd /IMPLIB:build\temp.win-amd64-2.7\Release\_mysql.lib /MANIFESTFILE:build\temp.win-amd64-2.7\Release\_mysql.pyd.manifest /MANIFEST LINK : fatal error LNK1181: cannot open input file 'mysqlclient.lib' error: command 'C:\\Program Files (x86)\\Common Files\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\amd64\\link.exe' failed with exit status 1181
我没有find一个“MySQL Connector / C”包的版本,仍然可以下载和VC9的作品。 在此vc9版本的vs12或vs14目录中使用mysqlclient.lib文件会导致无法parsing的符号。
我的问题是:
pip install mysqlclient
,获得正确的头文件(例如mysql.h
)和库(例如mysqlclient.lib
),需要使用哪些软件包? pip install mysqlclient
的先决条件是什么?