Mac OS Installation Instructions¶
Warning
If you want to install the bleeding-edge or development version of Theano from GitHub, please make sure you are reading the latest version of this page.
There are various ways to install Theano dependencies on a Mac. Here we describe the process in detail with Anaconda, Homebrew or MacPorts but if you did it differently and it worked, please let us know the details on the theano-users mailing-list, so that we can add alternative instructions here.
Requirements¶
Note
We only support the installation of the requirements through conda.
- Python == 2.7* or ( >= 3.3 and < 3.6 )
- The conda distribution is highly recommended. Python 2.4 was supported up to and including the release 0.6. Python 2.6 was supported up to and including the release 0.8.2. Python 3 is supported past the 3.3 release.
- NumPy >= 1.9.1 <= 1.12
- Earlier versions could work, but we don’t test it.
- SciPy >= 0.14 < 0.17.1
- Only currently required for sparse matrix and special functions support, but highly recommended. SciPy >=0.8 could work, but earlier versions have known bugs with sparse matrices.
- BLAS installation (with Level 3 functionality)
- Recommended: MKL, which is free through Conda with
mkl-service
package.- Alternatively, we suggest to install OpenBLAS, with the development headers (
-dev
,-devel
, depending on your Linux distribution).
Optional requirements
clang
(the system version)- Highly recommended. Theano can fall back on a NumPy-based Python execution model, but a C compiler allows for vastly faster execution.
- nose >= 1.3.0
- Recommended, to run Theano’s test-suite.
- Sphinx >= 0.5.1, pygments
- For building the documentation. LaTeX and dvipng are also necessary for math to show up as images.
- pydot-ng
- To handle large picture for gif/images.
- NVIDIA CUDA drivers and SDK
- Highly recommended Required for GPU code generation/execution on NVIDIA gpus. See instruction below.
- libgpuarray
- Required for GPU/CPU code generation on CUDA and OpenCL devices (see: GpuArray Backend).
- pycuda and skcuda
- Required for some extra operations on the GPU like fft and solvers. We use them to wrap cufft and cusolver. Quick install
pip install pycuda scikit-cuda
. For cuda 8, the dev version of skcuda (will be released as 0.5.2) is needed for cusolver:pip install pycuda; pip install git+https://github.com/lebedov/scikit-cuda.git#egg=scikit-cuda
.
Requirements installation through Conda (recommended)¶
Install Miniconda¶
Follow this link to install Miniconda.
Note
If you want fast compiled code (recommended), make sure you have Clang
installed.
Install requirements and optional packages¶
conda install numpy scipy mkl <nose> <sphinx> <pydot-ng>
- Arguments between <...> are optional.
Install and configure the GPU drivers (recommended)¶
Warning
OpenCL support is still minimal for now.
Install CUDA drivers
- Follow this link to install the CUDA driver and the CUDA Toolkit.
- You must reboot the computer after the driver installation.
- Test that it was loaded correctly after the reboot, executing the command nvidia-smi from the command line.
Note
Sanity check: The bin subfolder should contain an nvcc program. This folder is called the cuda root directory.
- Fix ‘lib’ path
- Add the ‘lib’ subdirectory (and/or ‘lib64’ subdirectory if you have a
64-bit OS) to your
$LD_LIBRARY_PATH
environment variable.
- Add the ‘lib’ subdirectory (and/or ‘lib64’ subdirectory if you have a
64-bit OS) to your
Set Theano’s config flags
To use the GPU you need to define the cuda root. You can do it in one of the following ways:
- Define a $CUDA_ROOT environment variable to equal the cuda root directory, as in
CUDA_ROOT=/path/to/cuda/root
, or - add a
cuda.root
flag toTHEANO_FLAGS
, as inTHEANO_FLAGS='cuda.root=/path/to/cuda/root'
, or - add a [cuda] section to your .theanorc file containing the option
root = /path/to/cuda/root
.
- Define a $CUDA_ROOT environment variable to equal the cuda root directory, as in
Attention
For MacOS you should be able to follow the above instructions to setup CUDA, but be aware of the following caveats:
- If you want to compile the CUDA SDK code, you may need to temporarily revert back to Apple’s gcc (
sudo port select gcc
) as their Makefiles are not compatible with MacPort’s gcc.- If CUDA seems unable to find a CUDA-capable GPU, you may need to manually toggle your GPU on, which can be done with gfxCardStatus.
Attention
Theano officially supports only clang on OS X. This can be installed by getting XCode from the App Store and running it once to install the command-line tools.
Installation¶
Stable Installation¶
With conda
¶
If you use conda, you can directly install both theano and pygpu. Libgpuarray will be automatically installed as a dependency.
conda install theano pygpu
Warning
Last conda packages for theano (0.9) and pygpu (0.6*) currently don’t support Python 3.4 branch.
With pip
¶
If you use pip, you have to install Theano and libgpuarray separately.
theano¶
Install the latest stable version of Theano with:
<sudo> pip install <--user> Theano[test, doc]
- Any argument between <...> is optional.
- Use sudo for a root installation.
- Use user for a user installation without admin rights. It will install Theano in your local site-packages.
- [test] will install the requirements for testing.
- [doc] will install the requirements in order to generate the documentation.
If you encountered any trouble, head to the Troubleshooting page.
The latest stable version of Theano is 0.9.0
(tagged with rel-0.9.0
).
libgpuarray¶
For the stable version of Theano you need a specific version of libgpuarray,
that has been tagged v0.6.2
.
Download it with:
git clone https://github.com/Theano/libgpuarray.git
cd libgpuarray
git checkout tags/v0.6.2 -b v0.6.2
and then follow the Step-by-step instructions.
Bleeding-Edge Installation (recommended)¶
Install the latest, bleeding-edge, development version of Theano with:
<sudo> pip install <--user> <--no-deps> git+https://github.com/Theano/Theano.git#egg=Theano
- Any argument between <...> is optional.
- Use sudo for a root installation.
- Use user for a user installation without admin rights. It will install Theano in your local site-packages.
- Use no-deps when you don’t want the dependencies of Theano to be installed through pip. This is important when they have already been installed as system packages.
If you encountered any trouble, head to the Troubleshooting page.
libgpuarray¶
Install the latest, development version of libgpuarray following the Step-by-step instructions.
Developer Installation¶
Install the developer version of Theano with:
git clone git://github.com/Theano/Theano.git
cd Theano
<sudo> pip install <--user> <--no-deps> -e .
- Any argument between <...> is optional.
- Use sudo for a root installation.
- Use user for a user installation without admin rights. It will install Theano in your local site-packages.
- Use no-deps when you don’t want the dependencies of Theano to be installed through pip. This is important when they have already been installed as system packages.
- -e makes your installation editable, i.e., it links it to your source directory.
If you encountered any trouble, head to the Troubleshooting page.
libgpuarray¶
Install the latest, development version of libgpuarray following the Step-by-step instructions.
Requirements through Homebrew (not recommended)¶
Install python with homebrew:
$ brew install python # or python3 if you prefer
This will install pip. Then use pip to install numpy, scipy:
$ pip install numpy scipy
If you want to use openblas instead of Accelerate, you have to install numpy and scipy with hombrew:
$ brew tap homebrew/python
$ brew install numpy --with-openblas
$ brew install scipy --with-openblas
Requirements through MacPorts (not recommended)¶
Using MacPorts to install all required Theano dependencies is easy, but be aware that it will take a long time (a few hours) to build and install everything.
MacPorts requires installing XCode first (which can be found in the Mac App Store), if you do not have it already. If you can’t install it from the App Store, look in your MacOS X installation DVD for an old version. Then update your Mac to update XCode.
Download and install MacPorts, then ensure its package list is up-to-date with
sudo port selfupdate
.Then, in order to install one or more of the required libraries, use
port install
, e.g. as follows:$ sudo port install py27-numpy +atlas py27-scipy +atlas py27-pip
This will install all the required Theano dependencies. gcc will be automatically installed (since it is a SciPy dependency), but be aware that it takes a long time to compile (hours)! Having NumPy and SciPy linked with ATLAS (an optimized BLAS implementation) is not mandatory, but recommended if you care about performance.
You might have some different versions of gcc, SciPy, NumPy, Python installed on your system, perhaps via Xcode. It is a good idea to use either the MacPorts version of everything or some other set of compatible versions (e.g. provided by Xcode or Fink). The advantages of MacPorts are the transparency with which everything can be installed and the fact that packages are updated quite frequently. The following steps describe how to make sure you are using the MacPorts version of these packages.
In order to use the MacPorts version of Python, you will probably need to explicitly select it with
sudo port select python python27
. The reason this is necessary is because you may have an Apple-provided Python (via, for example, an Xcode installation). After performing this step, you should check that the symbolic link provided bywhich python
points to the MacPorts python. For instance, on MacOS X Lion with MacPorts 2.0.3, the output ofwhich python
is/opt/local/bin/python
and this symbolic link points to/opt/local/bin/python2.7
. When executingsudo port select python python27-apple
(which you should not do), the link points to/usr/bin/python2.7
.Similarly, make sure that you are using the MacPorts-provided gcc: use
sudo port select gcc
to see which gcc installs you have on the system. Then execute for instancesudo port select gcc mp-gcc44
to create a symlink that points to the correct (MacPorts) gcc (version 4.4 in this case).At this point, if you have not done so already, it may be a good idea to close and restart your terminal, to make sure all configuration changes are properly taken into account.
Afterwards, please check that the
scipy
module that is imported in Python is the right one (and is a recent one). For instance,import scipy
followed byprint scipy.__version__
andprint scipy.__path__
should result in a version number of at least 0.7.0 and a path that starts with/opt/local
(the path where MacPorts installs its packages). If this is not the case, then you might have some old installation ofscipy
in yourPYTHONPATH
so you should editPYTHONPATH
accordingly.Please follow the same procedure with
numpy
.This is covered in the MacPorts installation process, but make sure that your
PATH
environment variable contains/opt/local/bin
and/opt/local/sbin
before any other paths (to ensure that the Python and gcc binaries that you installed with MacPorts are visible first).MacPorts does not create automatically
nosetests
andpip
symlinks pointing to the MacPorts version, so you can add them yourself with$ sudo ln -s /opt/local/bin/nosetests-2.7 /opt/local/bin/nosetests $ sudo ln -s /opt/local/bin/pip-2.7 /opt/local/bin/pip