Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using pip in windows

I installed distribute and pip using the links I have just given. I also installed the Microsoft Visual C++ 2008 redistributable package. However when I try to use pip.exe I get

error: Unable to find vcvarsall.bat

How can I fix this?

like image 648
marshall Avatar asked May 14 '13 20:05

marshall


2 Answers

Installing the Microsoft Visual C++ 2008 Redistributable Package is not sufficient to compile packages. You need to install a compiler, not just the support files.

There are three ways to do this:

  1. Install Visual C++.
  2. Use mingw's port of gcc instead of Visual C++.
  3. Use cygwin's port of gcc instead of either, and a cygwin build on Python instead of the native one.

If you want to go with option 1, you need to install Visual C++ itself. The free version should work just as well as the paid version, as long as you're not going to build binary packages to redistribute to others. Unfortunately, I'm not sure where to find the 2008 version anymore. As of May 2013, the download page only has 2010 and 2012.

When you install this, it will create a batch file called vcvarsall.bat (not vcvarshall.bat!), and give you the option of putting that batch file in your PATH. Running that batch file sets up a DOS prompt for building with that version of Visual C++. (This is handy if you have multiple versions of Visual C++, or other compilers, around.) If you skip that option, you will have to do it manually.

This question shows how to use a newer Visual Studio with older Python, and also shows how to point distutils at a vcvarsall.bat that's not on your PATH, and has links to a whole lot of other relevant questions and blog posts.


Many people find option 2 simpler. Install mingw, modify your PATH in the environment to include C:\MinGW\bin (or wherever you choose to install it), and pass -c mingw32 whenever you run a setup.py script.

The problem is that it's not as clearly documented how to tell easy_install and pip to use mingw instead of VC++. To do that, you need to find or create a distutils.cfg file, find or create a [build] section within it, and add compiler=mingw32. Not too hard. This blog post looks like it explains things pretty well, or see this answer.


Option 3 is by far the simplest. Install cygwin, tell it to install the Python and gcc packages, and you're done.

The problem is that you don't have native Windows Python, you have a Unix Python running in a fake Unix environment on top of Windows. If you like Cygwin, you'll love this; otherwise, you won't.

like image 81
abarnert Avatar answered Oct 13 '22 11:10

abarnert


You'll receive such error only for packages (or one of package's dependencies) that has CPython extensions. Pip internally:

  • downloads the source
  • runs distutils python setup install
  • install prepares setup files and tries to build CPython extensions in windows environment
  • windows environment calls MS Visual Studio vcvarsall.bat script which setups DOS environment variables to enable MS Visual Studio's C compiler in the shell
  • if vcvarsall.bat is not found - you'll get this message

Usual solution

For python libraries which have CPython extensions that are portable on windows, it is usual to have windows binary package, which are downloadable from pypi or library web site.

In such cases it is more suitable (and painless) to install library by downloading and running windows binary package.

There is a feature request for pip to Add support for installation of binary distutils packages on Windows.

New way to do it - wheels

Thanks to comment from @warren-p: That feature request has been superseeded by Wheels support in PIP.

Official description: A wheel is a ZIP-format archive with a specially formatted filename and the .whl extension.

As I have understood, if there is windows binary package with extension .whl then start by installing wheel first:

# Make sure you have the latest pip that supports wheel
pip install --upgrade pip
pip install wheel  

and then install .whl like this:

pip install full-path-or-url-to-your-library.whl

References:

  • pythonwheels.com
  • https://pypi.python.org/pypi/wheel
  • http://wheel.readthedocs.org/en/latest/
like image 32
Robert Lujo Avatar answered Oct 13 '22 10:10

Robert Lujo