2

I have the "Enthought Canopy" v1.5 distribution of Python 2.7 installed with cython 0.22 (installed via the Canopy package manager) on a Windows 64-bit computer. Trying to compile a cython file leads to the following error:

building 'my_cython_extension' extension
error: Could not find Visual Studio 2008 in your path.

If you do not have Visual Studio 2008 installed, you can use
the MinGW compiler instead. To install mingw, do:
    enpkg mingw
To use the MinGW compiler to build an extension module, use
the '-c' flag, e.g.:
    python setup.py build_ext -c mingw64
Note that building Python extensions with MinGW is not officially
supported, although it is known to work in many cases.

Visual Studio 2008 is no longer available, and Visual Studio 2008 Express doesn't include a 64-bit compiler. I've read that it's necessary to compile cython with the same compiler that Python was compiled with, which rules out using a newer version of Visual Studio. Additionally, the message clearly states that MinGW is not officially supported.

I've tried installing "Microsoft Visual C++ Compiler for Python 2.7" as per the Cython Wiki, but that has no effect on making the above error message disappear. I've read that updating setuptools may fix this error (as it can find the compiler in different locations than the old version expects to find it), but that didn't work for me, and additionally Enthought have stated on their website that:

Setuptools 0.6 is already supported, and higher versions are not yet compatible with Enthought installers.

... so updating setuptools may break something in Canopy.

Finally, I've tried installing "MS Windows SDK for Windows 7 and .NET Framework 3.5 SP1" as written later on in the cython Wiki, but this also had no effect on making the message disappear, and additionally it's a huge unwieldy package which I'd rather not install just for the compiler if possible.

So, is there a way to get "Microsoft Visual C++ Compiler for Python 2.7" working with cython and Enthought Canopy? If not, what is the official way to install and configure the cython compiler?

2 Answers 2

3

It took me the greater part of a day to figure out how to get this working, and I sincerely hope there's a better way, which I would love to hear, but this is what got the job done for me:

1) Install Microsoft Visual C++ 2008 Express edition -- you should find a direct download link by Googling for it.

2) Download the "Microsoft Windows SDK for Windows 7 and .NET Framework 3.5 SP1 (ISO)" image (be sure to choose the 64-bit version GRMSDKX_EN_DVD.iso) from here

3) Extract the iso with 7-zip, or mount / burn it with your preferred software

4) Run setup.exe and install. You can probably safely deselect everything except for "Visual C++ Compilers" and "Windows Headers and Libraries"

5) Copy the file C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\vcvars64.bat to the folder C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\amd64\ and rename it to vcvarsamd64.bat

6) Not sure if this is necessary, but you may need to run the following commands in the Visual Studio command prompt, as written in the cython wiki

set DISTUTILS_USE_SDK=1
setenv /x64 /release

Note 1: Step 1 appears to be necessary because the 64-bit Windows SDK for .net 3.5 doesn't seem to come with a vcvarsall.bat file.

Note 2: Step 5 is necessary because the vcvarsall.bat that comes with Visual C++ 2008 Express points to the wrong location for the 64-bit compiler.

2

(Enthought Support Here)

For the most up to date info, see our Knowledge Base that summarizes issues and provides useful links to some of the needed components for building extensions on Windows (as well other platforms)

Regarding the "Microsoft Visual C++ Compiler for Python 2.7", we are working on updating Canopy's Python version to 2.7.9 in our next release, which will include needed changes to support Microsoft's new compiler. We expect Canopy 1.5.3 to be released sometime next week.

For using the SDK now, the steps we recommend are:

  1. Download the Windows SDK for Python 2.7 as either a web installer or a DVD ISO.
  2. Install the SDK.

  3. Once the SDK is installed, you need to start the SDK Command Prompt and set two environment variables before compiling your extensions:

    set DISTUTILS_USE_SDK=1 
    setenv /x64 /release
    

    Assuming you didn't change the default SDK install path, this should look like:

    C:\Program Files\Microsoft SDKs\Windows\v7.0>set DISTUTILS_USE_SDK=1
    C:\Program Files\Microsoft SDKs\Windows\v7.0>setenv /x64 /release
    

    (Note: you may need to swap /x64 for /x86 if on a 32-bit system.)

From what I understand, using the SDK Command Prompt to set these variables will help avoid all of the extra configuration/surgery surrounding vcvarsall.bat.

4
  • Thanks, this doesn't actually answer my question though... It would be better if you could stick to the stackoverflow Q&A style. A few comments: 1) Visual Studio 2008 full is no longer available so it's unreasonable to expect users to install it. 2) The Windows SDK by itself (at least from the ISO) does not lead to a working compiler in Canopy x64, as it doesn't come with a vcvarsall.bat script 3) Supporting the Windows "C++ compiler for Python 2.7" would make this infinitely easier... IMO you should focus your answer on that part of my question (expected timeline for support?, etc)
    – Tim Rae
    Commented Mar 11, 2015 at 2:00
  • so when are you going to update setuptools in canopy?
    – Tim Rae
    Commented Mar 12, 2015 at 2:24
  • I have updated the Cython wiki for a manual workaround to support Visual C++ compiler for Python 2.7, it should work for whatever extension you want to compile (not just Cython): github.com/cython/cython/wiki/CythonExtensionsOnWindows
    – gaborous
    Commented Apr 6, 2015 at 14:23
  • I have the same problem and your answer didn't help to solve it. It still shows an error "Could not find Visual Studio 2008 in your path"
    – Serhiy
    Commented May 16, 2015 at 10:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.