Installing PygraphViz on Windows, Python 2.6 - python

Anybody out there has successfully installed PygraphViz on Windows?
Since there is not an official release for Windows, I'm trying to build it myself, but it fails to compile. I'm not the first one to face this issue, but I could not find an answer.
This is the console output:
C:\Python26\Lib\site-packages\pygraphviz-0.99.1>c:\python26\python.exe setup.py
install
library_path=C:/Program Files/Graphviz2.26.3/lib/debug/dll
include_path=C:/Program Files/Graphviz2.26.3/include/graphviz
running install
running build
running build_py
running build_ext
building 'pygraphviz._graphviz' extension
C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\cl.exe /c /nologo /Ox /MD /W
3 /GS- /DNDEBUG "-IC:/Program Files/Graphviz2.26.3/include/graphviz" -Ic:\python
26\include -Ic:\python26\PC /Tcpygraphviz/graphviz_wrap.c /Fobuild\temp.win32-2.
6\Release\pygraphviz/graphviz_wrap.obj
graphviz_wrap.c
warning: I don't know what to do with 'runtime_library_dirs': ['C:/Program Files
/Graphviz2.26.3/lib/debug/dll']
error: don't know how to set runtime library search path for MSVC++
Any help would be appreciated!

I appreciate this may be an obsolete thread by now, but to update it for others currently hitting this wall, the installer at Christoph Gohlke's Unofficial Windows Binaries for Python Extension Packages has just worked for me..

Here's what worked for me in Python 2.7. I assume it should work similarly in Python 2.6.
Precondition: Install mingw32 (included in pythonxy distrib if you're using it), Graphviz
1) Download pygraphviz sources
2) Edit setup.py to change paths to smth like
library_path=r"c:\Program Files (x86)\Graphviz 2.28\bin"
include_path=r"c:\Program Files (x86)\Graphviz 2.28\include\graphviz"
Note that it's \bin, not \lib. Linking with libs didn't work for me.
3) run python setup.py build -c mingw32
Result of step 3:
c:\Python27\Lib\site-packages\pygraphviz-1.1>python setup.py build -c mingw32
library_path=c:\Program Files (x86)\Graphviz 2.28\bin
include_path=c:\Program Files (x86)\Graphviz 2.28\include\graphviz
running build
running build_py
running build_ext
building 'pygraphviz._graphviz' extension
C:\MinGW32-xy\bin\gcc.exe -mno-cygwin -mdll -O -Wall "-Ic:\Program Files (x86)\G
raphviz 2.28\include\graphviz" -Ic:\Python27\include -Ic:\Python27\PC -c pygraph
viz/graphviz_wrap.c -o build\temp.win32-2.7\Release\pygraphviz\graphviz_wrap.o
pygraphviz/graphviz_wrap.c: In function 'agattr_label':
pygraphviz/graphviz_wrap.c:2855:5: warning: return makes integer from pointer wi
thout a cast
writing build\temp.win32-2.7\Release\pygraphviz\_graphviz.def
C:\MinGW32-xy\bin\gcc.exe -mno-cygwin -shared -s build\temp.win32-2.7\Release\py
graphviz\graphviz_wrap.o build\temp.win32-2.7\Release\pygraphviz\_graphviz.def "
-Lc:\Program Files (x86)\Graphviz 2.28\bin" -Lc:\Python27\libs -Lc:\Python27\PCb
uild "-Wl,-Rc:\Program Files (x86)\Graphviz 2.28\bin" -lcgraph -lcdt -lpython27
-lmsvcr90 -o build\lib.win32-2.7\pygraphviz\_graphviz.pyd
4) copy the result from the just built lib.win32-2.7 (single sub-folder called pygraphviz) into your Python's site-packages folder
Enjoy!

I've just ran into the same problem myself today. It isn't much of an answer, but I read in their FAQ:
Q:
How do I compile pygraphviz under
Windows? And why don’t you distribute
a pygraphviz Windows installer?
A:
We don’t have Windows development
machines but would like to have
pygraphviz work on all platforms. If
you have success with Windows or would
be willing to help test and distribute
a Windows installer please drop us a
note.
See also ticket 67:
https://networkx.lanl.gov/ticket/67
This, together with multiple unanswered pleas for help on various forums, mailing lists and newsgroups, lead me to believe that running PyGraphviz on Windows isn't something that can be done simply today.
So I did the next obvious thing (*) and fired up my Ubuntu on top of VirtualBox to create Graphviz graphs with Python. Curiously, it fails to install from source on Ubuntu as well, unless you have Graphviz itself installed from source, but it can be installed from a pre-built package with sudo apt-get python-pygraphviz.
So now I'm a happy pygraphviz user. Or at least 90% happy. PGV shows a os.popen3 deprecation warning on Python 2.6, and a 18-month-old ticket with a patch on this issue still hasn't been incorporated. Argh!
(*) I do it more and more lately...

If you remove the 'runtime_library_dirs' parameter from the extension dictionary in on line 147 in setup.py, your error message goes away. However, it can't find cgraph.lib. If you change your settings to
library_path=r'C:\Program Files\Graphviz2.26.3\lib\debug\lib'
everything complies and installs. You can import the modules, but the moment you try and access anything, it bombs out. In looking at the source for GraphViz, it appears that the windows version is C#/.NET - perhaps that is the source of our problems?

Hat the same problem and I finally got it to work! The problem was actually in Python's msvc9compiler.py (yes you do need VS8's vc9 to compile, too). The error comes on line 698 in the function runtime_library_dir_option(). Instead of having it throw an error, have it return the same string as library_dir_option():
def runtime_library_dir_option(self, dir):
return "/LIBPATH:" + dir
Then compile and it should work.

Alternately, you can try to use easy_install and avoid compiling. I installed "distribute", a fork of easy_install. But it also requires pkg-config, and you either have to compile that or get an older version. Furthermore, you also have to add pkg-config to the application path.

I managed to compile pygraphviz under windows with the following setup:
Windows 7,
WinPython-32bit-2.7.6.3,
Graphviz2.38,
microsoft visual c++ 2008 express edition,
pygraphvize 1.3 dev
in setup.py changed lines 35 and 36 to:
include_dirs = r"C:\Program Files\Graphviz2.38\include"
library_dirs = r"C:\Program Files\Graphviz2.38\lib\release\lib"
The compilation works and you get a working pygraphviz python module.
Hopes this helps.

This works for me, Python 2.7 32 bit, PyGraphViz 2.38, VCForPython27, Windows 10 64 bit.
First, install VCForPython27, see http://aka.ms/vcpython27.
Then, execute the following command, so that distutils.msvc9compiler can find the VC compiler. (This needs Administrator privilege. And if your Windows is 32 bit, you need to adjust the registry key.)
reg add HKLM\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\9.0\Setup\VC -v productdir -t REG_SZ -d "%LocalAppData%\Programs\Common\Microsoft\Visual C++ for Python\9.0" -f
Finally, install PyGraphViz.
set INCLUDE=C:\Program Files (x86)\Graphviz2.38\include
set LIB=C:\Program Files (x86)\Graphviz2.38\lib\release\lib
pip install pygraphviz

Related

Python, error (error: Unable to find vcvarsall.bat) installing a module (docx) [duplicate]

Using pip install zipline on Windows 8 with Python 2.7 gives me the error:
Downloading/unpacking six (from python-dateutil==2.1->delorean->zipline[all])
Running setup.py egg_info for package six
Installing collected packages: blist, pytz, requests, python-dateutil, six
Running setup.py install for blist
building '_blist' extension
error: Unable to find vcvarsall.bat
Complete output from command C:\Python27\python.exe -c "import setuptools;__
file__='c:\\users\\ThatsMe\\appdata\\local\\temp\\pip-build-ThatsMe\\blist\\setup.py';ex
ec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" inst
all --record c:\users\ThatsMe\appdata\local\temp\pip-xvoky2-record\install-record.tx
t --single-version-externally-managed:
running install
running build
running build_py
running build_ext
building '_blist' extension
error: Unable to find vcvarsall.bat
Question: How can the error be resolved? Running pip install zipline[all] gives the same error...
The problem here is the line 292 (Using Python 3.4.3 here) in $python_install_prefix/Lib/distutils/msvc9compiler.py which says:
VERSION = get_build_version()
This only checks for the MSVC version that your python was built with. Just replacing this line with your actual Visual Studio version, eg. 12.0 for MSVC2013
VERSION = 12.0
will fix the issue.
UPDATE: Turns out that there is a good reason why this version is hardcoded. MSVC C runtime is not required to be compatible between major versions. Hence when you use a different VS version you might run into runtime problems. So I advise to use VS 2008 (for Python 2.6 up to 3.2) and VS2010 for (Python 3.3 and later) until this issue is sorted out.
Binary compatibility will arrive with VS 2015 (see here) along with Python 3.5 .
For Python 2.7 users Microsoft released a special Microsoft Visual C++ Compiler for Python 2.7 which can be used without installing the whole VS 2008.
You could use ol' good easy_install zipline instead.
easy_install isn't pip but one good aspect of it is the ability to download and install binary packages too, which would free you for the need having VC++ ready. This of course relies of the assumption that the binaries were prepared for your Python version.
UPDATE:
Yes, Pip can install binaries now!
There's a new binary Python archive format (wheel) that is supposed to replace "eggs". Wheels are already supported by pip. This means you'll be able to install zipline with pip without compiling it as soon as someone builds the wheel for your platform and uploads it to PyPI.
If you are getting this error on Python 2.7 you can now get the Microsoft Visual C++ Compiler for Python 2.7 as a stand alone download.
If you are on 3.3 or later you need to install Visual Studio 2010 express which is available for free here: https://www.visualstudio.com/downloads/download-visual-studio-vs#d-2010-express
If you are 3.3 or later and using a 64 bit version of python you need to install the Microsoft SDK 7.1 that ships a 64 bit compiler and follow the directions here Python PIP has issues with path for MS Visual Studio 2010 Express for 64-bit install on Windows 7
First, you should look for the file vcvarsall.bat in your system.
If it does not exist, I recommend you to install Microsoft Visual C++ Compiler for Python 2.7. This will create the vcvarsall.bat in "C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0" if you install it for all users.
The problem now is in the function find_vcvarsall(version) in the C:/Python27/Lib/distutils/msvc9compiler.py module, which is looking for the vcvarsall.bat file.
Following the function calls you will see it is looking for an entry in the registry containing the path to the vcvarsall.bat file. It will never find it because this function is looking in other directories different from where the above-mentioned installation placed it, and in my case, the registry didn't exist.
The easiest way to solve this problem is to manually return the path of the vcvarsall.bat file. To do so, modify the function find_vcvarsall(version) in the msvc9compiler.py file with the absolute path to the vcvarsall.bat file like this:
def find_vcvarsall(version):
return r"C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat"
This solution worked for me.
If you already have the vcvarsall.bat file you should check if you have the key productdir in the registry:
(HKEY_USERS, HKEY_CURRENT_USERS, HKEY_LOCAL_MACHINE or HKEY_CLASSES_ROOT)\Software\Wow6432Node\Microsoft\VisualStudio\version\Setup\VC
Where version = msvc9compiler.get_build_version()
If you don't have the key just do:
def find_vcvarsall(version):
return <path>\vcvarsall.bat
To understand the exact behavior check msvc9compiler.py module starting in the find_vcvarsall(version) function.
Simply because you don't have c++ compiler installed there in your machine, check the following
Download Microsoft Visual C++ 2008 from this page. That is a generally useful page anyway, so you should probably bookmark it. For Python 3.3+ use MS Visual C++ 2010.
Install it.
Open Windows explorer (the file browser) and search for the location of ‘vcvarsall.bat’ and cut it to your clipboard.
run regedit from the Windows start key. You will need admin privilges.
Add a registry entry to
HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\VisualStudio\9.0\Setup\VC\ProductDir (64 bit Windows) or
HKEY_LOCAL_MACHINE\Software\Microsoft\VisualStudio\9.0\Setup\VC\ProductDir (32 bit)
as described here.
Hint: 0.9 in the registery directory is the currently installed version of your visual studio, if you running VS 2013, you have to find the path HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\VisualStudio\12.0....
At the Windows start key, type cmd to get a command shell. If you need to, go to your virtual environment and run activate.bat.
pip install or whatever you use to install it.
You need to have Visual Studio's bin dir in your path. Pip install is trying to compile some C code.
I spent hours researching this vcvarsall.bat as well. Most answers on SO focus on Python 2.7 and / or creating workarounds by modifying system paths. None worked for me. This solution worked out of the box for Python 3.5 and (I think) is the "correct" way of doing it.
See this link -- it describes the Windows Compilers to use for different versions of Python: https://wiki.python.org/moin/WindowsCompilers#Microsoft_Visual_C.2B-.2B-_14.0_standalone:_Visual_C.2B-.2B-_Build_Tools_2015_.28x86.2C_x64.2C_ARM.29
For Python 3.5, download this: https://www.microsoft.com/en-us/download/details.aspx?id=49983
For me, I had to run C:\Program Files (x86)\Microsoft Visual C++ Build Tools\Visual C++ x64 Native Build Tools Command Prompt for it to work. From that command prompt, I ran "pip install django_compressor" which was the particular package that was causing me an issue, and it worked perfectly.
Hope this saves someone some time!
Thanks to "msoliman" for his hint, however his answer doesn't give clear solution for those who doesn't have VS2010
For example I have VS2012 and VS2013 and there are no such KEYs in system registry.
Solution:
Edit file: "[Python_install_loc]/Lib/distutils/msvc9compiler.py"
Change on line 224:
productdir = Reg.get_value(r"%s\Setup\VC" % vsbase,
"productdir")
to:
productdir = "C:\Program Files (x86)\Microsoft Visual Studio [your_vs_version(11/12...)]\VC"
and that should work
If you are trying to install matplotlib in order to work with graphs on python. Try this link.
https://github.com/jbmohler/matplotlib-winbuild.
This is a set of scripts to build matplotlib from source on the MS Windows platform.
To build & install matplotlib in your Python, do:
git clone https://github.com/matplotlib/matplotlib
git clone https://github.com/jbmohler/matplotlib-winbuild
$ python matplotlib-winbuild\buildall.py
The build script will auto-detect Python version & 32/64 bit automatically.
I appreciate this might not be the answer to resolving on 3.4 but I tried a huge variety of things to fix this on 3.4 and thought this might be useful if someone is time pressed or doesn't have the know-how to correct it (in my case, work demands).
With exactly the same setup, I found that my installation problems only happened with Python 3.4. When I changed to 2.7, all my issues seemed to be resolved.
We have a rather overzealous security setup though so I'm going to try the same on my home version (still 3.4) and see if I have any more joy. My inclination is that my VS version has somehow been restricted and the answers above should help. If I find anything more tonight I'll add further detail.
This is my first reply, not the most technical I'm afraid!

How to install snappy C libraries on Windows 10 for use with python-snappy in Anaconda?

I want to install parquet for python using pip within an Anaconda 2 installation on Windows 10.
While installing I ran into the error that is described here, the installer can't find snappy-c.h.
There is no mention on how to install this on Windows in the answers.
I downloaded the Snappy library from http://google.github.io/snappy/ and now I'm stuck.
From my error message I would have assumed that the header files need to be in C:\Users\...\AppData\Local\Continuum\Anaconda2\include, but in the downlaoded archive header and library files are just all in the same folder.
How do I install these properly in the Anaconda folder?
Full error message:
Building wheels for collected packages: python-snappy
Running setup.py bdist_wheel for python-snappy ... error
Complete output from command C:\Users\...\AppData\Local\Continuum\Anaconda2\python.exe -u -c "import setup
tools, tokenize;__file__='c:\\users\\...\\appdata\\local\\temp\\pip-build-kl4zef\\python-snappy\\setup.py';f=ge
tattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec
'))" bdist_wheel -d c:\users\...\appdata\local\temp\tmpt8fz9bpip-wheel- --python-tag cp27:
running bdist_wheel
running build
running build_py
creating build
creating build\lib.win-amd64-2.7
copying snappy.py -> build\lib.win-amd64-2.7
running build_ext
building '_snappy' extension
creating build\temp.win-amd64-2.7
creating build\temp.win-amd64-2.7\Release
C:\Users\...\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe /c /nol
ogo /Ox /MD /W3 /GS- /DNDEBUG -IC:\Users\...\AppData\Local\Continuum\Anaconda2\include -IC:\Users\...
\AppData\Local\Continuum\Anaconda2\PC /Tpsnappymodule.cc /Fobuild\temp.win-amd64-2.7\Release\snappymodule.obj
snappymodule.cc
snappymodule.cc(31) : fatal error C1083: Cannot open include file: 'snappy-c.h': No such file or directory
error: command 'C:\\Users\\...\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\V
C\\Bin\\amd64\\cl.exe' failed with exit status 2
After a really long and frustrating time trying different methods to get the C files working, I found this site:
http://www.lfd.uci.edu/~gohlke/pythonlibs/
Where C. Gohlke has kindly compiled and uploaded the files for us windows users.
Just download the version you need based on your system and python version. I am using 64bits and python 3.6, so I used the following command from my download folder:
pip install python_snappy-0.5-cp36-cp36m-win_amd64.whl
It worked like a charm :)
It seems there are now Conda packages that should simplify things (in Anaconda). I was able to do (on Python 3.6, Windows 10):
conda install -c conda-forge snappy
conda install -c conda-forge python-snappy
EDIT: Refer to the other answers in this thread, I only keep this up for reference.
Here's the steps it took me to install Snappy and Python-Snappy on Windows 10:
Install cygwin.
Download snappy from http://google.github.io/snappy/ and unpack it somewhere into the cygwin directory.
Write AM_PROG_AR into configure.ac above LT_INIT and run autogen.sh from the cygwin terminal, install missing cygwin packages if needed.
Copy snappy-c.h into the Anaconda2/include folder and libsnappy.a into the Anaconda2/Lib folder (in ~/AppData/Local/Continuum/).
stdint.h was missing for Visual C++ Compiler for Python 2.7., I found it here and put it into ~\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\include.
Installing python-snappy should now work without throwing any errors.
If you get problems and weird imports check if the SnapPy library is also installed and deinstall it because it causes a conflict.
(Everything works fine now.)
EDIT: No it does not. This method is not reliable, once you try to update you run into new problems. And installing on Python 3 is another monster that isn't tackled by this solution.

Installing pygrib Package

Apologies in advance for what is probably a bad/poorly phrased question, but I merely dabble in programming and am very unfamiliar with under the hood aspects of package installation, etc.
Basically, I am trying to install the pygrib package (available here: https://github.com/jswhit/pygrib) via a cygwin terminal.
I am running Python 2.7.3 32-bit on Windows 10.
Originally I encountered the missing vcvarsall.bat error the first time I tried to run 'python seteup.py build' and followed the advice here: error: Unable to find vcvarsall.bat
After installing the MS Visual Studio package, I have made it past that error and to another I do not understand with the following output:
$ python setup.py build
reading from setup.cfg...running build
running build_py
running build_ext
skipping 'pygrib.c' Cython extension (up-to-date)
building 'pygrib' extension
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -IC:\Users\Matthew\Anaconda2\lib\site-packages\numpy\core\include -I/usr/local\include -I/usr/local\include -I/usr/local\include/jasper -I/usr/local\include -I/usr\include -I/usr\include -Ig2clib_src -IC:\Users\Matthew\Anaconda2\include -IC:\Users\Matthew\Anaconda2\PC /Tcpygrib.c /Fobuild\temp.win32-2.7\Release\pygrib.obj
pygrib.c
c:\users\matthew\anaconda2\lib\site-packages\numpy\core\include\numpy\npy_1_7_deprecated_api.h(12) : Warning Msg: Using deprecated NumPy API, disable it by #defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
pygrib.c(242) : fatal error C1083: Cannot open include file: 'grib_api.h': No such file or directory
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\VC\\BIN\\cl.exe' failed with exit status 2
Obviously it's still looking for some other files, or needs other environment variables defined, but I'm at a loss as to how to proceed and I'm far from an expert when it comes to any of this.
I'd also be glad to try something completely different if you have a better way to go about this process entirely.
I have tried pip and the conda installer, but have not had any luck with them either.
Thank you in advance for anything you can offer.
Better to use linux on virtual machine within Windows ten. Then you can install pygrib without pain. As you are trying to play with meteorological data, it is recommended to install Linux and it will help you at may places. There is even Anaconda has a package (only for Linux and Mac). You can install using:-
conda install -c conda-forge pygrib=2.0.1
For your specif case following link might be useful:-
https://github.com/jswhit/pygrib/issues/19
https://github.com/jswhit/pygrib/pull/18 and https://github.com/conda-forge/ecmwf_grib-feedstock/issues/5
Gud luck.
for python 3 i needed to install it directly with linux package manager
sudo apt-get install python3-grib
To use: pip install pygrib
you need to install python3-grib:
sudo apt install python3-grib
NOTE:
Ubuntu Linux:
python3-grib requires libeccodes-dev
if later you install libgrib-api-dev it requires libgrib-api-dev.
which is not compatable with libgrib-api-dev
Meaning, if you install libgrib-api-dev after you install python3-grib you break the python3-grib installation.
Take me a while also, but this way was very simple and efficient. I then installed it on pycharm.
and on anaconda with
pip install pyproj
pip install pygrib
I am using Anaconda on Windows 10.
I have accessed Anaconda Prompt for the environment that I wanted to install the package.
In there, I have started by installing pyproj:
pip install pyproj
And then:
conda install -c conda-forge pygrib

Python does not consider distutils.cfg

I have tried everything given and the tutorials all point in the same direction about using mingw as a compiler in python instead of visual c++.
I do have visual c++ and mingw both. Problem started coming when I wanted to install using pip. It always gave Unable to find vcvarsall.bat
So as per suggestions I created a file distutils.cfg under the following path c:/python27/Lib/distutils/ and added the following two lines:
[build]
compiler=mingw32
However, this file has no effect whatsoever. The same error still exists while using pip. I am trying to install numpy by the way currently although the error came earlier also.
Cost me several hours to figure this out but now works like a charm.
I am on Windows 64bit and using a scientific Python distribution Enthought Canopy.
Ensure you have installed MinGW and the Compilers you need (C, C++, Fortran..)
Add C:\MingW\bin to your PATH in Environment variables
In C:\Users\MyName\AppData\Local\Enthought\Canopy32\App\appdata\canopy-1.6.2.3262.win-x86\Lib\distutils, create with notepad++ or similiar a new file distutils.cfg
Write and save:
[build]
compiler = mingw32
[build_ext]
compiler = mingw32
Difficult Solution (Building using the C/C++ compiler)
Are you on Windows 32bit or 64bit? Are you specifying the build when you're compiling? For example, do the following in your shell or bash:
python setup.py build --compiler==mingw32
python setup.py install
Easier Solution (Use pre-built binaries)
If you don't have to compile the program, you can use the unofficial Windows binaries from here
Do you happen to use virtualenv as well?
Anyway, use Microsoft Visual C++ Compiler for Python 2.7
and a newer setuptools. The one bundled with virtualenv (3.6) does not support this compiler.
pip install "setuptools>=6.0"
Credits: http://blog.ionelmc.ro/2014/12/21/compiling-python-extensions-on-windows/

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?
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:
Install Visual C++.
Use mingw's port of gcc instead of Visual C++.
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.
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/
You can download Visual Studio 2008 Express SP1 from
http://visual-studio-2008.en.malavida.com/
You can deselect the two add to browser options it offers.
I found these links on microsoft.com that still work to Install Visual C++.
http://download.microsoft.com/download/8/B/5/8B5804AD-4990-40D0-A6AA-CE894CBBB3DC/VS2008ExpressENUX1397868.iso
2008 SP1 here
http://download.microsoft.com/download/E/8/E/E8EEB394-7F42-4963-A2D8-29559B738298/VS2008ExpressWithSP1ENUX1504728.iso

Categories

Resources