Difference between revisions of "Modules:FourDAnalysis-Documentation-3.6-SciPy-Memo"

From Slicer Wiki
Jump to: navigation, search
Line 90: Line 90:
 
  $ export LDFLAGS="-arch x86_64"
 
  $ export LDFLAGS="-arch x86_64"
 
  $ export FFLAGS="-arch x86_64"
 
  $ export FFLAGS="-arch x86_64"
 +
$ export CFLAGS="-arch x86_64"
  
 
Once you configure site.cfg and the environment variables, you're ready to run setup.py:
 
Once you configure site.cfg and the environment variables, you're ready to run setup.py:

Revision as of 05:56, 28 April 2011

Home < Modules:FourDAnalysis-Documentation-3.6-SciPy-Memo

Go back to 4D Analysis Module for 3D Slicer 3.6

About this page

This is a memo on how to set up SciPy in 3D Slicer version 3, for those who are interested in 4D Analysis module. This page explains how to build SciPy package from the source. Please note that building SciPy is not always straightforward, due to its dependencies on other libraries e.g. BLAS, LAPACK, etc, and the author of this page cannot answer to questions regarding installation of SciPy. This page only provides the steps that worked for the author's computer environment for the users information.

Installation

Please refer the official SciPy website for the instruction. The following sections describe the author's experience of installing SciPy in 3D Slicer.

Mac OS X (tested on 10.6.7, Tested on April 24, 2011)

The following steps were based on the following web page, but modified for 3D Slicer

Before Installation...

If you have MacPorts or any other UNIX package manager, please make sure that your environment variable PATH doesn't contain any paths to those directories. For example, do not have /opt/local/bin in Mac OS with MacPort installed. Some tools in those paths may screw up the installing process.

Install GNU Fortran

To build SciPy, you need to have GNU Fortran compiler. The official SciPy instruction recommends gfortran-4.2.3 available at [1]

Install 3D Slicer version 3 (latest revision)

Please follow the 3D Slicer Build Instructions, except that:

  • You download the latest source code instead of stable release branch. The latest source code is available in the subversion repository at http://svn.slicer.org/Slicer3/trunk
  • Turn off NumPy by editing slicer_variables.tcl. The variable that controls NumPy building is around line 250. Please edit it as:
set ::USE_NUMPY "OFF"

Install UMF

We will use Slicer3-lib/python as a working directory. First, obtain UMFPACK, UFConfig, and AMD:

cd ~/tmp
wget http://www.cise.ufl.edu/research/sparse/umfpack/current/UMFPACK.tar.gz
wget http://www.cise.ufl.edu/research/sparse/UFconfig/current/UFconfig.tar.gz
wget http://www.cise.ufl.edu/research/sparse/amd/current/AMD.tar.gz
tar xf AMD.tar.gz 
tar xf UFconfig.tar.gz 
tar xf UMFPACK.tar.gz

Before start building, configure UMFConfig/UMFConfig.mk:

F77 = gfortran
CFLAGS = -O3 -fno-common -no-cpp-precomp -fexceptions -arch x86_64
LIB = -lstdc++
BLAS = -framework Accelerate
LAPACK = -framework Accelerate
UMFPACK_CONFIG = -DNCHOLMOD

Then run the following commands:

cp UFconfig/UFconfig.h AMD/Include/
cp UFconfig/UFconfig.h UMFPACK/Include/
cd UMFPACK
make

This ends up with the following message, but just ignore the errors (?)

/usr/bin/ranlib: file: libumfpack.a(umf_di_dump.o) has no symbols
/usr/bin/ranlib: file: libumfpack.a(umf_dl_dump.o) has no symbols
/usr/bin/ranlib: file: libumfpack.a(umf_zi_dump.o) has no symbols
/usr/bin/ranlib: file: libumfpack.a(umf_zl_dump.o) has no symbols
ranlib libumfpack.a
ranlib: file: libumfpack.a(umf_di_dump.o) has no symbols
ranlib: file: libumfpack.a(umf_dl_dump.o) has no symbols
ranlib: file: libumfpack.a(umf_zi_dump.o) has no symbols
ranlib: file: libumfpack.a(umf_zl_dump.o) has no symbols
( cd Demo   ; make )
( cd ../../CHOLMOD ; make library )
/bin/sh: line 0: cd: ../../CHOLMOD: No such file or directory
make[2]: *** No rule to make target `library'.  Stop.
make[1]: *** [../../CHOLMOD/Lib/libcholmod.a] Error 2
make: *** [all] Error 2

Install NumPy/SciPy

We will use Slicer3-lib/python as a working directory as we did for UMF. First, download the source code:

$ cd <Slicer3 working directory>/Slicer3-lib/python
$ git clone https://github.com/numpy/numpy.git
$ git clone https://github.com/scipy/scipy.git
$ cd numpy

To make NumPy with AMD and UMFPACK built above, copy site.cfg.example to site.cfg in the numpy directory and put the following line:

[amd]
library_dirs = <Path to the 3D Slicer working directory>/Slicer3-lib/python/umfpack/AMD/Lib
include_dirs = <Path to the 3D Slicer working directory>/Slicer3-lib/python/umfpack/AMD/Include
amd_libs = amd

[umfpack]
library_dirs = <Path to the 3D Slicer working directory>/Slicer3-lib/python/umfpack/UMFPACK/Lib
include_dirs = <Path to the 3D Slicer working directory>/Slicer3-lib/python/umfpack/UMFPACK/Include
umfpack_libs = umfpack

Before compiling NumPy and SciPy, set the following environment variables. If you are using bash (default in Mac OS X)

$ export MACOSX_DEPLOYMENT_TARGET=10.6
$ export LDFLAGS="-arch x86_64"
$ export FFLAGS="-arch x86_64"
$ export CFLAGS="-arch x86_64"

Once you configure site.cfg and the environment variables, you're ready to run setup.py:

$ cd <Slicer3 working directory>/Slicer3-lib/python/numpy
$ ../../python-build/bin/python setup.py build --fcompiler=gnu95

If the setup.py fails with the following message, gfortran compiler is not found.

numpy.distutils.fcompiler.CompilerNotFound: gnu95: f90 nor f77

This can be solved by creating a symbolic link to the compiler in /usr/bin. For example:

$ sudo ln -s /usr/local/bin/i686-apple-darwin8-gfortran-4.2 /usr/bin/gfortran

Please note that "sudo ln -s /usr/local/bin/gfortran /usr/bin" doesn't work, since /usr/local/bin/gfortran is a symbolic link.

Then, you need to remove "/usr/local/bin" from PATH environment variable. You can check if gfortran is properly by typing the following commands:

$ which gfortran
/usr/bin/gfortran
$ gfortran
gfortran: no input files

To install NumPy to the copy of Python in Slicer3-lib, run:

$ ../../python-build/bin/python setup.py install

SciPy can be installed by the following process:

$ cd <Slicer3 working directory>/Slicer3-lib/python/scipy
$ ../../python-build/bin/python setup.py build --fcompiler=gnu95
$ ../../python-build/bin/python setup.py install

To confirm that SciPy is installed correctly, run Python interpreter and try loading scipy package:

$ ../../python-build/bin/python
Python 2.6.6 (r266:163, Apr 21 2011, 14:29:38)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import scipy
>>>

Windows

Linux