4

I am trying to compile a simple cython extension from the example page here on my Windows 7 64-bit machine with Python 2.6 64-bit version installed. I installed Cython 0.15.1 for Windows 64-bit version from Gohlke's page.

Basically, the answer from here and here are not my options because I really do need Python 64-bit version to address larger memory. Also, because I am trying to compile using Microsoft SDK for .NET 4, I cannot use the approach in the latter solution.

I tried the steps here and observed the green window but compilation now throws the cannot find vcvarsall.bat error. Following is the sequence of commands I tried:

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

Setting SDK environment relative to C:\Program Files\Microsoft SDKs\Windows\v7.1\.
Targeting Windows 7 x64 Release

C:\Program Files\Microsoft SDKs\Windows\v7.1>e:

E:\>cd cython

E:\cython>python setup.py build_ext --inplace
running build_ext
skipping 'fib.c' Cython extension (up-to-date)
building 'fib' extension
error: Unable to find vcvarsall.bat

Any suggestions on how I solve this?

Community
  • 1
  • 1
Legend
  • 113,822
  • 119
  • 272
  • 400

3 Answers3

5

Here is an excerpt from one of my batch files:

rem Configure the environment for 64-bit builds.
rem Use "vcvars32.bat" for a 32-bit build.
"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\vcvars64.bat"
rem Convince setup.py to use the SDK tools.
set MSSdk=1
set DISTUTILS_USE_SDK=1 

The 7.1 SDK uses what is effectively VS2010 but Python 2.6 is compiled with VS2008. If you can use the 7.0 SDK (I think it is also known as the .NET 3.5 SDK), you will have access to VS2008's compiler. It is risky to mix different compilers and runtimes libraries.

casevh
  • 11,093
  • 1
  • 24
  • 35
  • +1 Thank you. I will try this out now. I somehow missed the fact about VS2008. I am currently downloading the .NET 3.5 SDK and will try this out. – Legend Nov 11 '11 at 00:48
  • You are a savior. Works flawlessly! Thank you once again. – Legend Nov 11 '11 at 01:11
5

The docs at http://wiki.cython.org/64BitCythonExtensionsOnWindows say:

For Python 2.6, 2.7 and 3.1, you should use the Microsoft Windows SDK for Windows 7 and .NET Framework 3.5 SP1. Later or earlier versions of the SDK will link with the wrong C runtime. Note that later versions of Python is likely to require a more recent version of the Windows SDK. This is required to make sure the extension is linked with the same C runtime version as Python. Using the correct version of the SDK is the only way to control this with Microsoft's build tools.

Thomas K
  • 39,200
  • 7
  • 84
  • 86
0

Microsoft have a c compiler package specifically for Python 2.7 now.

I suggest you use that instead of the SDK and VS. The VS express edition doesn't have the 64-bit compiler, which is why you need the SDK, in theory. I tried installing the SDK but it didn't help. If you don't need the SDK or VS for anything else, uninstall them and use the compilers from http://www.microsoft.com/en-gb/download/details.aspx?id=44266.

In the event that you still have problems once you install the compilers, my answer on pyusb 2.7 windows install error may be helpful.

Community
  • 1
  • 1
geoff22873
  • 51
  • 4
  • Note that [link-only answers are discouraged](http://meta.stackoverflow.com/tags/link-only-answers/info), SO answers should be the end-point of a search for a solution (vs. yet another stopover of references, which tend to get stale over time). Please consider adding a stand-alone synopsis here, keeping the link as a reference. – kleopatra Feb 13 '15 at 14:04