Ubuntu安装说明¶
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.
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
python-dev
,g++
>= 4.2- 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
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.
通过系统包安装先决条件(不推荐)¶
If you want to acquire the requirements through your system packages and install them system wide follow these instructions:
For Ubuntu 16.04 with cuda 7.5
sudo apt-get install python-numpy python-scipy python-dev python-pip python-nose g++ libopenblas-dev git
sudo pip install Theano
# cuda 7.5 don't support the default g++ version. Install an supported version and make it the default.
sudo apt-get install g++-4.9
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 20
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 10
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30
sudo update-alternatives --set cc /usr/bin/gcc
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30
sudo update-alternatives --set c++ /usr/bin/g++
# Work around a glibc bug
echo -e "\n[nvcc]\nflags=-D_FORCE_INLINES\n" >> ~/.theanorc
For Ubuntu 11.10 through 14.04:
sudo apt-get install python-numpy python-scipy python-dev python-pip python-nose g++ libopenblas-dev git
On 14.04, this will install Python 2 by default. If you want to use Python 3:
sudo apt-get install python3-numpy python3-scipy python3-dev python3-pip python3-nose g++ libopenblas-dev git
sudo pip3 install Theano
For Ubuntu 11.04:
sudo apt-get install python-numpy python-scipy python-dev python-pip python-nose g++ git libatlas3gf-base libatlas-dev
手动Openblas安装(已弃用)¶
The openblas included in some older Ubuntu version is limited to 2 threads. Ubuntu 14.04 do not have this limit. If you want to use more cores at the same time, you will need to compile it yourself. Here is some code that will help you.
# remove openblas if you installed it
sudo apt-get remove libopenblas-base
# Download the development version of OpenBLAS
git clone git://github.com/xianyi/OpenBLAS
cd OpenBLAS
make FC=gfortran
sudo make PREFIX=/usr/local/ install
# Tell Theano to use OpenBLAS.
# This works only for the current user.
# Each Theano user on that computer should run that line.
echo -e "\n[blas]\nldflags = -lopenblas\n" >> ~/.theanorc