visual studio - Compiling Python modules on Windows x64 -
i'm starting out projects in words processing , needed numpy , nltk. first time got know easy_install , how compile new module of python system.
i have python 2.7 x64 plus vs 11 , vs 12. cygwin (the latest 1 guess). see in file compiles using vs looks vs env same version 1 compiled python code, why? when hardcoded 11.0 version, numpy failed build on several strange errors regarding vcvarsall (it found vcvarsall, misused it).
can't build python binaries on windows? if not, can cross compile on linux windows? (using same method google android sdk)
update: zooba mentions below, free x86 , amd64 (x86-64) vc90 c-compilers python-2.7 available microsoft.
update: patch vcvarsall.bat use x64 compilers sdk v7.0 directly pip in shell instead of using sdk shell , setting distutils_use_sdk , mssdk environmental variables in directions below. see fix vcvarsall.bat install python-2.7 x64 extensions v90 instead of sdk7.
tl;dr: use windows sdk v7.0 compilers, open sdk shell , call
c:\> setenv /release /x64 c:\> set distutils_use_sdk=1 c:\> mssdk=1 to build python 2.7.x extensions using distutils, pip or easy_install. see python x64 package extensions pip, msvc 2008 express & sdk 7.
note: can install numpy optimized using intel mkl christoph gohlke. virtualenv's, try converting binary distribution windows installer wheel file can installed pip. building numpy source not trivial. has become possibility recent introduction , availability of openblas, fork of gotoblas. there optimized binaries available windows x86 , x86-64 source relatively simpler compile gotoblas or atlas.
note: in past hadn't recommended compiling numpy source because had optimize blas platform time-intensive, , reference blas (fortran) or cblas (c/c++) implementations relatively low-performing. numpy depends on lapack depends on blas additional hurdle building numpy. openblas binaries compiled lapack, obstacle has been removed. see carl kleffner's static mingw-w64 toolchains build numpy openblas on windows - has resolved of abi incompatibilities , issues linking correct microsoft visual c common runtime library (msvcr90.dll python-2.7).
so onward main question installing python extensions on windows 7 x64.
the recommended way compile extensions use same compiler used compile python shared library [1-3]. official python 2.7.x windows compiled using microsoft visual c++ compilers version 9.0 [4] (aka msvc90 or vc90) microsoft visual studio 2008 professional, might able free microsoft dreamspark. evidentally x64 compilers not installed default, make sure installed along x86 compilers. note: ms visual studio 2008 may no longer available, ms visual studio 2010 let use msvc90 toolchain if installed, can installed windows sdk7.
you can tell version python built looking @ header when execute python interpreter command line. e.g.: python 2.7.3 (default, apr 10 2012, 23:24:47) [msc v.1500 64 bit (amd64)] on win32 means built vs 2008 c++. can build python source, arduous task. in general not recommended mix compiler runtimes, although in practice may find still work.
if have heart set on using gnu gcc, have use mingw-w64 because mingw native x86 applications, not amd64/x86-64. need to
- create distutils config file specify mingw compiler,
- remove -mno-cygwin bug distutils.cygwinccompiler.mingw32ccompiler and
- export library definitions file using either
pexports.exemsys orgendef.exemsys2 , make static librarylibpython27.ausingdlltool.exe(msys/msys2) (but newest releases of official python windows have file inpython27\libfolder, thanks!).
however in end still need link against runtime python built with, msvcr90.dll, need visual c++ 2008 redistributable. note: windows gcc mingw-w64 uses msvcrt.dll not same msvcr90.dll or later.
if want free can use microsoft visual c++ 2008 express sp1 need add windows sdk 7 .net frameworks 3.5 sp1 because express version not have x64 compilers. procedure installing x64 c++ extensions vs2008 express & sdk 7 similar on cython site windows x64 extensions. note: ms visual studio 2008 express no longer available or supported.
fyi: not need visual studio build using microsoft compilers. available free appropriate sdk package. cl.exe compiler executable, have set whatever platform options configured autotools or other tool such cmake. cmake plays msvc, autotools afaik doesn't work msvc , require posix environment , utilities on windows available in msys.
for many python packages use distutils or setuptools, can compile extensions using windows sdk 7 following directions posted in various places through reference documentation , wikis:
- from start menu select all programs microsoft windows sdk v7.0 , start cmd shell open command window optimized windows sdk.
step #1 equivalent of typing following in run box start menu or command prompt (aka
c:\windows\system32\cmd.exe):%comspec% /e:on /v:on /k "%programfiles%\microsoft sdks\windows\v7.0\bin\setenv.cmd"note: flags
/e:on, enables command extensions, ,/v:on, enables delayed variable expansion, both necessarysetenv.cmdfunction, or message x64 compilers not installed, &c.then type
setenv /release /x64set sdk environment variables windows 7 x64 release (vs debug or x86 default).- type
set distutils_use_sdk=1hit return , typeset mssdk=1, return telldistutils.msvccompilerusing sdk, , sdk determine of environment variables. - now use installation method of choice:
pip install pyyaml ntlkrecommended way, see ntlk, must have setuptools , pip installed.python setup.py installeach downloaded, extracted tarballeasy_install pyyaml ntlkold way , way install eggs.
[1] building c , c++ extensions on windows
[2] distutils.msvccompiler — microsoft compiler
[3] python dev guide: getting started: windows
[4] what version of visual studio python compiled with
Comments
Post a Comment