I am trying to install the mysqlclient Python package (https://pypi.python.org/pypi/mysqlclient) into a virtual Python 2.7 environment on Windows 7 (on a local PC, and on the Appveyor CI) and cannot get it done.
I am describing the issues for the local PC with Win 7, but it happens basically the same way on Appveyor.
Packages in my virtualenv when I start:
pip (9.0.1)
setuptools (36.6.0)
wheel (0.30.0)
pip install mysqlclient initially says:
. . .
running build_ext
building '_mysql' extension
error: Microsoft Visual C++ 9.0 is required. Get it from http://aka.ms/vcpython27
Apparently, Python 2.7 requires VC9. After installing it, pip install mysqlclient gets a little further, but misses include files:
. . .
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
In order to get the header files, I installed the "MySQL Connector/C 6.1.10" from https://downloads.mysql.com/archives/get/file/mysql-connector-c-6.1.10-winx64.msi. This is admittedly only the second latest version, but I need to install it on Appveyor from the command line, and did not find out how to download the latest version in an unattended manner.
Also, using the MSI installer installs the package in C:\Program Files\MySQL\MySQL Connector C 6.1 but the build step in pip install expects it in C:\Program Files (x86)\MySQL\MySQL Connector C 6.1, so I softlinked it:
mklink /D "C:\Program Files (x86)\MySQL\MySQL Connector C 6.1" "C:\Program Files\MySQL\MySQL Connector C 6.1"
When looking at the files in that version of the MySQL Connector/C, it has only lib/vs12 and lib/vs14 directories:
lib/vs12/mysqlclient.lib
lib/vs14/mysqlclient.lib
As expected, pip install mysqlclient now gets beyond the compiles, but fails when linking:
. . .
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
I did not find a version of the "MySQL Connector/C" package that can still be downloaded and that works with VC9. Using the mysqlclient.lib files in the vs12 or vs14 directories in this vc9 build results in unresolved symbols.
My questions are:
What package(s) do I need to use in order to get the right header files (e.g. mysql.h) and libraries (e.g. mysqlclient.lib) for a successful pip install mysqlclient on Windows 7?
More generally, what are the prerequisites for a successful pip install mysqlclient on Windows 7?
download mysqlclient from http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python
choose the version matching your python version, example mysqlclient‑1.4.2‑cp37‑cp37m‑win_amd64.whl, and then:
pip install wheel
pip install mysqlclient‑1.4.2‑cp37‑cp37m‑win_amd64.whl
Incidentally I ran into the same issue in July last year and only now finished an entry on my blog about it.
Basically, you're not going to like it, but you need to re-compile mysqlclient from scratch, because -- as you pointed out -- it's not available for Visual Studio 9 since a long time.
However, doing it right is somewhat tricky, because you need to fix some compilation issues that apparently aren't documented anywhere in Oracle's official documentation. There are also issues with the Python setup.py file, as it doesn't care about the platform architecture and always looks in the x86 directory. That's why you soft-linked the directory. There is an open issue on Github mentioning this.
So basically, using the VC++ for Python 2.7 you already installed:
Download the Oracle MySQL C Connector source code.
Download and install Microsoft Visual C++ Compiler for Python 2.7.
Use CMake to generate NMake Makefiles for the MySQL C Connector source code. Pay attention to environment variables, see this Github issue comment.
Compile the MySQL C Connector mysqlclient library using nmake mysqlclient.
Install the MySQL C Connector binary and add the compiled mysqlclient.
Run pip install mysqlclient again.
Step 4 is tricky, because Microsoft don't supply C99 stdint.h, inttypes.h and stdlib.h is missing lldiv_t. You can use this StackOverflow post to get stdint.h and inttypes.h and then manually define lldiv_t in decimal.h as:
typedef struct {
long long quot;
long long rem;
} lldiv_t;
You can also copy these headers from a newer Visual Studio, like 2013 and 2015. After that, as you had already figured out, you need to put the compiled mysqlclient.lib into C:\Program Files (x86)\MySQL\MySQL Connector C 6.1\lib\vs9.
Then issue another pip install mysqlclient and you're all done.
I am trying to install Scrapy via the project interpreter but I end with the error. Later I tried installing using pip install Scrapy but I end up with the same error. The error details are:
running build_ext
generating cffi module 'build\\temp.win-amd64-2.7\\Release\\_padding.c'
already up-to-date
generating cffi module 'build\\temp.win-amd64-2.7\\Release\\_constant_time.c'
already up-to-date
generating cffi module 'build\\temp.win-amd64-2.7\\Release\\_openssl.c'
already up-to-date
building '_openssl' extension
C:\Users\xxxx\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -IC:\Python27\include "-IC:\aaaa\PC" /Tcbuild\temp.win-amd64-2.7\Release\_openssl.c /Fobuild\temp.win-amd64-2.7\Release\build\temp.win-amd64-2.7\Release\_openssl.obj
_openssl.c
build\temp.win-amd64-2.7\Release\_openssl.c(434) : fatal error C1083: Cannot open include file: 'openssl/opensslv.h': No such file or directory
error: command 'C:\\Users\\xxxx\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\amd64\\cl.exe' failed with exit status 2
You could be missing Microsoft C++ for Python 2, since the file that cannot be opened is from it.
The download is here: https://www.microsoft.com/en-us/download/details.aspx?id=44266
I'm trying to install portfolioopt (Win 8.1*64) lib using pip and get those errors:
C:\Users\Alexey\AppData\Local\Programs\Common\Microsoft\Visual C++ for Pytho
n\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -IC:\Anaconda\inc
lude -IC:\Anaconda\PC /Tcsrc/C/base.c /Fobuild\temp.win-amd64-2.7\Release\src/C/
base.obj
base.c
c:\users\alexey\appdata\local\temp\pip-build-30y6av\cvxopt\src\c\cvxopt.h(31
) : fatal error C1083: Cannot open include file: 'complex.h': No such file or di
rectory
error: command 'C:\\Users\\Alexey\\AppData\\Local\\Programs\\Common\\Microso
ft\\Visual C++ for Python\\9.0\\VC\\Bin\\amd64\\cl.exe' failed with exit status
2
I already have Visual C++ 2008 and Compiler package for python 2.7. How to fix it?
It appears that your problem is with the requirements for portfolioopt, for some reason it doesn't seem to be properly installing the cvxopt package. What I did to fix this problem (I tried and had a similar problem to you) is to separately install the cvxopt package, which I did with this command:
conda install -c https://conda.binstar.org/eswears cvxopt
after this package installed I used the pip install command for the portfolioopt package:
pip install portfolioopt
and the installation worked.
I am Getting this Exception while installing packages in Python.
uninstalled python and installed it again but there is no
C:\Users\ramasastri.g\Desktop\pycrypto-2.6>python setup.py install
running install
running build
running build_py
running build_ext
warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath.
building 'Crypto.Random.OSRNG.winrandom' extension
C:\Program Files\Microsoft Visual Studio 10.0\VC\BIN\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -Isrc/ -Isrc/inc-msvc/ -IC:\Python27\include -IC:\Python27\PC /Tcsrc/winrand.c /Fobuild\temp.win32-2.7\Release\src/winrand.obj
winrand.c
c:\python27\include\pyconfig.h(68) : fatal error C1083: Cannot open include file: 'io.h': No such file or directory
error: command '"C:\Program Files\Microsoft Visual Studio 10.0\VC\BIN\cl.exe"' failed with exit status 2
Probably you are missing the c++ compiler.
I installed it using a pre-packaged version from here
My problem was inside a virtualenv. I could not install some packages and got the same fatal error c1083. I was trying Visual Studio and PTVS. Just installing Microsoft Visual C++ Compiler for Python 2.7 https://www.microsoft.com/en-us/download/details.aspx?id=44266 was not enough to fix the error, despite it is needed.
I have found the solution here http://blog.ionelmc.ro/2014/12/21/compiling-python-extensions-on-windows/
The setuptools installed by virtualenv is too old (3.6). You need to remove it and reinstalling but, in the "Install python package" window in Visual Studio solution explorer, instead of using "setuptools" as the module name to install use "setuptools>=6.0".
Got the same error message and found the cause was that while I had set up the PATH variable correctly with the paths to Visual Studio and Python, I forgot to add the C:\Windows\System32 path.
Trying to install PIL via pip in my virtualenv. However I get this error.
C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -IlibImaging -Ic:\My_Pro
jects\testenv\include -Ic:\My_Projects\testenv\PC /Tc_imaging.c /Fobuild\temp.win32-2.7\Release\_imaging.obj
_imaging.c
_imaging.c(75) : fatal error C1083: Cannot open include file: 'Python.h': No such file or directory
error: command '"C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\cl.exe"' failed with exit status 2
----------------------------------------
Command c:\My_Projects\testenv\Scripts\python.exe -c "import setuptools;__file__='C:\\My_Projects\\testenv\\pinax-solcia
l-site\\build\\PIL\\setup.py';execfile(__file__)" install --single-version-externally-managed --record c:\users\darren\a
ppdata\local\temp\pip-fdzgwn-record\install-record.txt failed with error code 1
Storing complete log in C:\Users\Darren\AppData\Roaming\pip\pip.log
I looked over at this question which suggests installing python-dev but that user was on Ubuntu. I'm on WIndows 7 and not sure how to solve my issue.
Thanks.
It looks as if the VisualStudio compiler is not finding the Python development sources.
Maybe you need to set a specific environment variable?
This blog post seems to suggest that you need to add c:\Python27 and c:\Python27\bin to your path. Maybe that's what is missing?
PIL is also known for having issues with setuptools. Have you tried pillow?