Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python PIP has issues with path for MS Visual Studio 2010 Express for 64-bit install on Windows 7

I was creating a virtualenv with a clean install of python 3.3, 64-bit version. (Note: I have several installs of python on my computer including WinPython but want to set up clean and small virtualenvs for several projects that I am working on. The WinPython version works just fine.) When I used pip to try to install packages, I got an error message (can include pip log if requested). Ultimately, the last lines of the error message were:

File "c:\python33-b\Lib\distutils\msvc9compiler.py", line 287, in query_vcvarsall raise ValueError(str(list(result.keys())))

ValueError: ['path']

I investigated the results from the function query_vcvarsall in the msvc9compiler.py. I found out that this function was looking for the path of vcvarsall from MS Visual Studio 10 Express on my computer. It is looking for 4 components: INCLUDE=, PATH=, LIB=, and LIBPATH=. These were specific for MS VS 2010. My install sent an argument of "amd64" to this function. It did not find anything but the PATH= statement but it did find the vcvarsall.bat file. When I tricked this function to use the "x86" argument, it found all of the 4 statements and appeared as if it would run fine.

I spent some time researching this on the web. I found that MS VS Express 2010 installs by default as 32-bit. One has to set it to run as 64-bit (which means it will set the statements needed above.) Apparently there was a bug and the 64-bit tools were not installed with this version. So I installed MS SDK in order to install the 64-bit tools. I then found there was a fix to this and installed that (listed below in links).

There were several methods outlined to create the paths for the 64-bit VS. One was to run vcvarsall amd64 on the command line for MS VS. This resulted in a message saying the tools were not installed on my computer. These tools were to reside in the C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64 directory. The file that it apparently is looking for is vcvars64.bat (or something similar). I have the directory but not the batch file. (There was a recommendation to use the x86_amd64 method but it has all of the same issues.)

The second recommendation was to run setenv /x64 from the SDK command line. I ran that and it seemed to run correctly. However, when I went I tried to install packages via pip, I got the same error message.

My question ultimately is how to get pip running smoothly? Just to mention, yes, I did reboot before I tested pip again after each install and attempt at fixing this.

Here are some sites that helped me get this far:

1) Launching a 64-bit command prompt from Visual Studio 2010

2) Setting the Path and Environment Variables for MS VS 2010 Command-Line Builds:
http://msdn.microsoft.com/en-us/library/f2ccy3wt.aspx

3) VS2010 Express and missing x64 compiler:
https://social.msdn.microsoft.com/Forums/en-US/e0ef4613-d90f-4eec-90db-41339ed31367/vs2010-express-and-missing-x64-compiler?forum=Vsexpressinstall

4) FIX: Visual C++ compilers are removed when you upgrade Visual Studio 2010 Professional or Visual Studio 2010 Express to Visual Studio 2010 SP1 if Windows SDK v7.1 is installed:
http://support.microsoft.com/kb/2519277

5) msvc9compiler.py: ValueError when trying to compile with VC Express: http://bugs.python.org/issue7511

like image 292
Stacy L. Gardner Avatar asked Oct 20 '14 19:10

Stacy L. Gardner


People also ask

How do we install pip in Python in Visual Studio?

Select the Run command: pip install matplotlib option. This option installs matplotlib , and any packages it depends on (in this case, that includes numpy ). Consent to elevation if prompted to do so. After the package installs, it appears in the Python Environments window.

Why is pip not installed with Python?

PIP installation is not added to the system variable – In order to be able to run Python commands from a CMD window, you will need to add the path of your PiP installation to your PATH in the system variable. If you installed Python using the installation executable, it should be added automatically.


2 Answers

Ultimately I was able to get pip running. In a nutshell (and redundant from info above) here is what I did to intall 64-bit packages for python 3.3:

1) Installed Microsoft Visual C++ 2010 Express Download Here (http://www.visualstudio.com/downloads/download-visual-studio-vs)

2) Installed Microsoft SDK 7.1 (Windows 7) (http://www.microsoft.com/en-us/download/details.aspx?id=8279)

3) Built/enabled the 64-bit tools in SDK. Go to start menu and under Microsoft Windows SDK v7.1 folder, select Windows SDK 7.1 Command Prompt. A shell will come up. Type the following command setenv /x64.

4) I installed a fix (don't know if it was ultimately needed.) (http://support.microsoft.com/kb/2519277)

5) Created a new vcvars64.bat file under C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64. Inside of that new batch file I included only the line CALL "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64. I am assuming what this does is forces distutils to use the C++ compiler from the SDK. Pip installed correctly after this. As I understand, the C++ compiler has to be the same as that used to compile python 3.3. From my research, it seems that the SDK as installed is that same compiler but just doesn't require that the original vcvars64.bat file be present. This information came from: http://www.w7forums.com/threads/vcvarsall-bat-no-64bit-support-vcvars64-bat-missing.6606/ . Please correct me if I am creating problems down the road with this solution. Thanks.

like image 89
Stacy L. Gardner Avatar answered Oct 03 '22 05:10

Stacy L. Gardner


For me it was sufficient to perform steps 1, 2 and 5, step 4 was not required:

1) Install Microsoft Visual C++ 2010 (in my case not Express)

2) Install Microsoft SDK 7.1 (Windows 7)

Skip 3 and 4.

5) Create C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64\vcvars64.bat containing the line CALL "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64

Done: pip3 install numpy works.

like image 40
jayesef Avatar answered Oct 03 '22 06:10

jayesef