Mac OS安装说明¶
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 The development package (python-dev or
- python-devel on most Linux distributions) is recommended (see just below). 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.11.1
- 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.
- 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.)
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 g++ (Windows/Linux) or Clang (OS X) 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¶
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.
libgpuarray¶
For the stable version of Theano you need a specific version of libgpuarray, that has been tagged v-9998
. Download it with:
git clone https://github.com/Theano/libgpuarray.git --tags
git checkout origin/v-9998
cd libgpuarray
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.
通过Homebrew安装要求的包(不推荐)¶
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
通过MacPorts安装要求的包(不推荐)¶
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
.然后,为了安装一个或多个必需的库,请使用
port install
,如下:$ 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.
为了使用MacPorts版本的Python,你可能需要使用
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). 执行此步骤后,你应该检查which python
提供的符号链接指向MacPorts Python。例如,在使用MacPorts 2.0.3的MacOS X Lion上,which python
的输出为/opt/local/bin/python
,此符号链接指向/opt/local/bin/python2.7
。当执行sudo port select python python27-apple
(你不应该这么做)时,链接指向/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. 然后执行例如sudo port select gcc mp-gcc44
以创建指向正确(MacPorts)gcc(本例中为4.4版)的符号链接。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). 例如import scipy
,接着print scipy.__version__
和print scipy.__path__
应导致版本号至少为0.7.0,路径以/opt/local
开始(MacPorts安装软件包的路径)。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