This is an archival dump of old wiki content --- see scipy.org for current material

If you already have Python installed, the easiest way to install Numpy and Scipy is to download and install the binary distribution from Download.

If you do not have Python installed on your system you can install the Enthought Python distribution which comes with Scipy and many other useful scientific tools. It is the easiest way to quickly get started with Scipy.


If you require optimal performance tuned to your platform, especially for linear algebra operations on larger matrices, you might have to build Numpy and Scipy yourself, depending on the availability of optimized binary packages at the linked location. Fortunately, the build of Numpy and Scipy is very easy and all the required software is freely available, so there's no need to worry. The following tutorial will explain in detail how to compile optimized Numpy and Scipy packages.

In addition to this page, the NiPy instructions for building Numpy and Scipy may be of use.

Table of contents

Supported Compilers

As pointed out in Installing_SciPy/BuildingGeneral, building Numpy and Scipy requires a C compiler. Furthermore, a Fortran 77 compiler is needed to build Scipy and to build a Lapack library for use in Numpy and Scipy.

The MinGW project provides windows versions of the free GNU compilers gcc and g77. These are the compilers most Scipy developers work with and hence the compilers that are supported the best by the Scipy build scripts.

Cygwin is a Posix compatible Linux-like environment for Windows. It is a very useful tool as it allows to compile and use many Unix tools without modification. We'll need it for the compilation of ATLAS. If selected during installation, Cygwin also makes available its own versions of the MinGW compilers (by the command line option "-mno-cygwin" to gcc), which produce identical code. There is no need to install the separate MinGW distribution when Cygwin is already installed.

Scipy also supports Visual C++ (MSVC) as the C/C++ compiler (currently only Numpy compiles without a modification). If one wants to build extension modules for the official binary distribution of Python, the runtime libraries have to be compatible. As the official versions of Python 2.3/2.4/2.5 are compiled with Visual Studio 2003 (Visual Studio 7.1) and hence linked to msvcr71, this leaves only MSVC 7.1 to build extensions for these Python versions. This pretty much excludes the free (as in beer) Visual Studio 2005 Express, at least if one doesn't also want to build Python (and all other extension modules) from sources with MSVC 8 - which currently is not offically supported. Combining MSVC with G77 from MinGW or Cygwin is supported, as is the combination with other Fortran compilers. [Could someone say something about Intel Fortran?]

Download and installation of compiler

Generally you only need one C compiler (and one Fortran compiler). Cygwin is required if you want to build ATLAS yourself.

MinGW:

The easiest way to install MinGW is to use the MinGW installer from here. The current (as of 3 August, 06) candidate distribution with gcc and g77 3.4.5 is reported to work best. After installation you need to put the MinGW\bin directory on the path.

Cygwin:

Cygwin can be conveniently installed and updated with http://www.cygwin.com/setup.exe Make sure that the gcc and gcc-mingw packages in the Devel section are selected. If you want to use the official Python distribution (recommended) and don't want to get confused, do not select the Python option in the Cygwin installer. The Cygwin tools should be used from within the Cygwin Bash shell available from the start menu after installation. This is a tutorial explaining the basics of Cygwin.

Visual Studio:

The installation does not need to be explained. The command line tools are most conveniently used from the Visual Studio command prompt available from the start menu.

Intel Math Kernel Library (MKL)

Update: According to Christoph Gohlke, he's successfully built numpy 1.4 and scipy 0.8dev in 64 (and 32?) bit Windows against MKL using MSVC 8 Pro, using just the default site.cfg, with this command:

> python setupscons.py scons -b --fcompiler=ifort --compiler=msvc

NumPy (not yet SciPy?) can be built using the optimized BLAS and LAPACK libraries within Intel's Math Kernel Library. MKL's implementation of BLAS and LAPACK are apparently better optimized for Intel chips than ATLAS's implementation.

Download the trial of MKL for Windows and install it. The trial is 30 days, but it's currently unknown what will happen to the library and header files on your hard drive after that period has expired.

You can use MKL to build with MSVC7.1, the same compiler used by Python >= 2.4. Make sure you have Visual Studio 2003 installed (will other compilers work?).

Build NumPy

Once you've checked out the source for NumPy, create an empty file called ".numpy-site.cfg" in your home directory (something like C:\Documents and Settings\username). Windows Explorer might not allow you to create a file starting with ".", so you may have to use the command line to rename it. Make sure you have a HOME user environment variable that points to your home directory (see Control Panel/System/Advanced/Environment Variables). Add the following to the file, substituting your MKL installation path where appropriate:

# config file for building numpy on ia32 platform,
# using Intel's Math Kernel Library for win32
# builds successfully with MSVC7.1
# replace C:\Program Files\Intel\MKL\9.0 with your Intel MKL install path

[mkl]
include_dirs = C:\Program Files\Intel\MKL\9.0\include
library_dirs = C:\Program Files\Intel\MKL\9.0\ia32\lib
mkl_libs = mkl_ia32, mkl_c_dll, libguide40
lapack_libs = mkl_lapack
# mkl_c or mkl_c_dll? either seem to work:
# mkl_c : "cdecl interface library"
# mkl_c_dll : "cdecl interface library for dynamic library"
# libguide or libguide40? either seem to work:
# libguide.lib : "Static threading library"
# libguide40.lib : "Interface library for dynamic threading library"

Check that the specified libraries can indeed be found by running:

python setup.py config

from the root NumPy source directory. Then, (as of numpy rev 3726) all that's required is running:

python setup.py install

from the root NumPy source directory. This should build NumPy without errors and install it to your site-packages directory. Finally, test your installation.

Build SciPy

(Not yet tested)

BLAS, LAPACK and ATLAS

Numpy and Scipy can be built with support for optimized BLAS and LAPACK libraries. (The supported BLAS interface is the CBLAS interface, not the Fortran 77 interface.)

Pre-built versions of the ATLAS libraries are available for several processors:

The rest of this section describes steps to build your own ATLAS libraries for Windows optimized for your processor.

On Windows currently only one widely available optimized CBLAS library is supported: ATLAS. The build script currently does not support Intel MKL on Windows. Neither is the ACML library from AMD directly supported, as its C interface for BLAS is incompatible. An optimized Lapack library can be built from the Fortran sources using an optimized BLAS library. (In principle one could also use CLAPACK to build LAPACK with a C compiler, but CLAPACK is known to have problems and its official distribution is not in sync with the latest patches available for Lapack.)

Numpy and Scipy in Windows can currently only make use of CBLAS and LAPACK as static libraries - DLLs are not supported.

ATLAS + LAPACK

If you don't yet have optimized static CBLAS and Lapack libraries, you can easily build them from within Cygwin. (Lapack also can just as easily be built with MinGW.)

Follow these steps to build ATLAS:

Now copy the files libatlas.a, libcblas.a, libf77blas.a and liblapack.a from ATLAS\lib\YOUR_ARCHITECTURE to a directory of your choice, for example c:\BlasLapackLibs.

Follow these steps to build LAPACK:

Now copy the file lapack_LINUX.a from LAPACK to your equivalent of the folder BlasLapackLibs created above.

Follow this step to get an ATLAS-optimized LAPACK library:

In Cygwin execute these commands in your BlasLapackLibs folder

ar x liblapack.a
ar r lapack_LINUX.a *.o
rm *.o
mv lapack_LINUX.a liblapack.a

You now have the files libcblas.a, libf77blas.a, liblapack.a and libatlas.a in your BlasLapackLibs folder, holding optimized static CBLAS, BLAS, (complete) LAPACK libraries and their low level ATLAS support library. If you want to use MSVC to build Numpy/Scipy, you have to rename the lib*.a files to *.lib, i.e. libcblas.a to cblas.lib, for instance.

In case you want to create a dll with the full BLAS, CBLAS and LAPACK interface (currently not relevant for Scipy), this could be easily done as follows:

gcc -mno-cygwin -shared -o blaslapack.dll -Wl,--out-implib=blaslapack.lib -Wl,--export-all-symbols -Wl,--allow-multiple-definition -Wl,--enable-auto-import -Wl,--whole-archive liblapack.a libf77blas.a libcblas.a -Wl,--no-whole-archive libatlas.a -lg2c

This generates a dll linked to msvcrt.dll. If you want to generate a dll (only) linked to msvcr71, using the command line option -lmsvcr71 is not enough (due to a bug in MinGW?), you need to replace -lmsvcrt in your gcc spec file (in Cygwin\lib\gcc\i686-pc-cygwin\3.4.X or MinGW\lib\gcc\mingw32\3.4.X, ) with -lmsvcr71 before executing the above command. If you want to check the dll dependencies, you could use depends.

The generated blaslapack.lib is the import library for linking the dll.

Build Numpy

First download and extract the latest source distribution from here, or check out the Subversion tree http://svn.scipy.org/svn/numpy/trunk/ using a tool like the excellent TortoiseSVN.

In order to configure Numpy to use your optimized BLAS/LAPACK libraries you need to copy the site.cfg.example file in the root directory of Numpy to site.cfg. If site.cfg.example does not exist, then just create a new site.cfg. Change its contents as follows:

If you've built ATLAS+LAPACK as described above:

[atlas]
library_dirs = c:\path\to\BlasLapackLibs
atlas_libs = lapack, f77blas, cblas, atlas

If you want to build numpy for the Cygwin-Python (usually you don't), you need to use the Cygwin path instead of the windows path.

If you want to use some other static BLAS and LAPACK libraries instead, use:

[blas]
library_dirs = c:\path\to\CBlas
blas_libs = cblas

[lapack]
library_dirs = c:\path\to\BlasLibs
lapack_libs = lapack

where "cblas" and "lapack" should be replaced with the names of your libraries (without lib*.a or .lib extensions).

Now change to the numpy root directory in a Windows command prompt window (or the Cygwin bash shell). If you want to compile with MinGW or Cygwin-MinGW, execute

c:\path\to\python.exe setup.py config --compiler=mingw32 build --compiler=mingw32 bdist_wininst

and if you want to compile with Visual Studio .2003, execute

c:\path\to\python.exe setup.py config --compiler=msvc build --compiler=msvc bdist_wininst

This leaves you with a nice binary installer in the dist subfolder, which you can use to install Numpy and later uninstall through "Add and remove programs" in the "Control panel".

If you'd rather just go ahead and actually install it somewhere, use:

c:\path\to\python.exe setup.py config --compiler=[compiler] build --compiler=[compiler] install --prefix=c:\where\to\install

If you want to compile and install Numpy for use with the Python from Cygwin (usually you don't), execute

python setup.py config --compiler=mingw32 build --compiler=mingw32 install

in the Cygwin Bash shell.

If you later wish to rebuild numpy, say after updating the code from SVN, it may be necessary to delete the "build" directory first before rerunning the above commands.



Miscellaneous Notes:

If you're getting a "gcc.lib not found" error, it is probably because you're building with --compiler=msvc, but you also have MinGW installed. In that case Numpy may compile some Fortran files using MinGW, and then at link time try to link with "gcc.lib" which doesn't exist in the MinGW distribution. You can fix this by copying some MinGW .a file to .lib files:

cd c:\MinGW\lib\gcc\mingw32\{compiler.version}\
copy libgcc.a   gcc.lib
copy c:\MinGW\lib\libg2c.a   .\g2c.lib

If you get link errors like this:

lapack.lib(zunmbr.o) : error LNK2001: unresolved external symbol _s_cat
lapack.lib(zunmqr.o) : error LNK2001: unresolved external symbol _s_cat
lapack.lib(dormql.o) : error LNK2001: unresolved external symbol _s_cat
lapack.lib(zunmql.o) : error LNK2001: unresolved external symbol _s_cat
lapack.lib(dormbr.o) : error LNK2001: unresolved external symbol _s_cat
lapack.lib(dormqr.o) : error LNK2001: unresolved external symbol _s_cat
lapack.lib(zhseqr.o) : error LNK2019: unresolved external symbol _s_cat referenced in function _zhseqr_
lapack.lib(zunmlq.o) : error LNK2001: unresolved external symbol _s_cat
lapack.lib(dhseqr.o) : error LNK2019: unresolved external symbol _s_cat referenced in function _dhseqr_
lapack.lib(dormtr.o) : error LNK2001: unresolved external symbol _s_cat
lapack.lib(zunmtr.o) : error LNK2001: unresolved external symbol _s_cat
lapack.lib(dormlq.o) : error LNK2001: unresolved external symbol _s_cat
lapack.lib(dlamch.o) : error LNK2019: unresolved external symbol _e_wsfe referenced in function _dlamc2_
lapack.lib(xerbla.o) : error LNK2001: unresolved external symbol _e_wsfe
lapack.lib(dlamch.o) : error LNK2019: unresolved external symbol _do_fio referenced in function _dlamc2_
lapack.lib(xerbla.o) : error LNK2001: unresolved external symbol _do_fio
lapack.lib(dlamch.o) : error LNK2019: unresolved external symbol _s_wsfe referenced in function _dlamc2_
lapack.lib(xerbla.o) : error LNK2001: unresolved external symbol _s_wsfe
lapack.lib(xerbla.o) : error LNK2019: unresolved external symbol _s_stop referenced in function _xerbla_
lapack.lib(ilaenv.o) : error LNK2019: unresolved external symbol _s_cmp referenced in function _ilaenv_
lapack.lib(ilaenv.o) : error LNK2019: unresolved external symbol _s_copy referenced in function _ilaenv_
lapack.lib(zlahqr.o) : error LNK2019: unresolved external symbol _z_abs referenced in function _zlahqr_
lapack.lib(zlanhe.o) : error LNK2019: unresolved external symbol _z_abs referenced in function _zlanhe_
lapack.lib(zgebal.o) : error LNK2019: unresolved external symbol _z_abs referenced in function _zgebal_
lapack.lib(zlange.o) : error LNK2019: unresolved external symbol _z_abs referenced in function _zlange_
lapack.lib(zlanhs.o) : error LNK2019: unresolved external symbol _z_abs referenced in function _zlanhs_
lapack.lib(zhseqr.o) : error LNK2019: unresolved external symbol __alloca referenced in function _zhseqr_
lapack.lib(zlarfx.o) : error LNK2019: unresolved external symbol __alloca referenced in function _zlarfx_
lapack.lib(zlahqr.o) : error LNK2019: unresolved external symbol _z_sqrt referenced in function _zlahqr_
build\lib.win32-2.4\numpy\linalg\lapack_lite.pyd : fatal error LNK1120: 10 unresolved externals

you need to add the g2c and gcc libraries to the ATLAS and LAPACK libraries you have already. With Cygwin, you can find these in /lib/gcc/i686-pc-mingw32/3.4.4. Copy them to g2c.lib and gcc.lib, respectively, and modify site.cfg accordingly.

Build SciPy

Download and extract the latest source distribution from here, or check out the Subversion tree http://svn.scipy.org/svn/scipy/trunk/.

If you want to configure further packages (like UMFPACK), copy the site.cfg from your Numpy source tree to the root of the Scipy tree. Otherwise the setup script will just use the site.cfg of the Numpy it finds on your PYTHONPATH. (In my experience it seems you at least need to have blas and lapack entries. Probably best to just put all three entries in there.)

[atlas]
library_dirs = c:\path\to\BlasLapackLibs
atlas_libs = lapack, f77blas, cblas, atlas

[blas]
library_dirs = c:\path\to\CBlas
blas_libs = cblas

[lapack]
library_dirs = c:\path\to\BlasLibs
lapack_libs = lapack

At this time (2006-07-13), the Scipy source can only be compiled using MinGW. It will not compile with MSVC. Furthermore, version 3.4.5 of gcc seems to be required or you end up with a linker error at the end. See above for how to get that. Note that there is no problem with using an MSVC-compiled Numpy with a MinGW-compiled Scipy.

[Further info required.]

How to build scipy-0.5.2 with cygwin gcc-3.4.4

I've successfully built scipy-0.5.2 with cygwin gcc-3.4.4. You should adjust your $F77FLAGS and/or $FFLAGS and add -fno-second-underscore option. I've built ATLAS, fftw-3.1.2, and UMFPACK with this option, and then, successfully built scipy. No linker error is reported. If you've built those libs without -fno-second-underscore in $FFLAGS/$F77FLAGS, just try adding it when building scipy, it may also work.

Once you've got the site.cfg ready, Scipy can be built and installed with the same command as Numpy. Namely, to make an installer exe:

c:\path\to\python.exe setup.py config --compiler=mingw32 build --compiler=mingw32 bdist_wininst

Or to install directly to a given location use:

c:\path\to\python.exe setup.py config --compiler=mingw32 build --compiler=mingw32 install --prefix=c:\where\to\install

Testing

After installation run the unit test suits in Python:

>>> import numpy, scipy
>>> numpy.test()
>>> scipy.test()

These should run without errors.

You may also wish to verify that numpy and scipy are using your optimized BLAS and LAPACK libraries by checking:

>>> import numpy, scipy
>>> numpy.show_config()
>>> scipy.show_config()

Troubleshooting

If you experience problems when building, installing or testing Numpy or Scipy, feel free to ask for help on the respective mailing list. Make sure your email includes the error output and version info on your operating system and the compilers you used.


Original author: Stephan Tolksdorf


CategoryInstallation

SciPy: Installing_SciPy/Windows (last edited 2015-10-24 17:48:23 by anonymous)