Install Theano Python Library in Ubuntu

In this tutorial, we shall learn how to install Theano Python Library in Ubuntu using Anaconda and pip. The steps are useful when you want to run older deep learning examples, reproduce legacy machine learning code, or follow tutorials that depend on the original Theano package.

Theano is a Python library used for defining, optimizing, and evaluating mathematical expressions, especially expressions involving multidimensional arrays. It was widely used in early deep learning workflows. For new projects, many developers now choose libraries such as TensorFlow or PyTorch, but Theano is still useful when maintaining or studying older code bases.

Prerequisites for Installing Theano on Ubuntu

We shall use Anaconda distribution of Python for developing Deep Learning Applications with Theano.

Install Anaconda Python.

Before installing Theano, open a terminal and check that Python and pip are available from the Anaconda installation.

</>
Copy
python --version
pip --version

If the commands point to your Anaconda directory, you can continue with the installation. If they point to the system Python installation, activate your Anaconda environment first.

Create a Separate Anaconda Environment for Theano

Theano is often used with older Python and NumPy versions. To avoid conflicts with your current Python projects, it is better to install Theano in a separate conda environment.

</>
Copy
conda create -n theano-env python=3.6 numpy scipy six pip
conda activate theano-env

The environment name theano-env is only an example. You may use any name that helps you identify the environment later.

Install Theano

To install Theano we shall use pip installer. Open a terminal and run the following command.

$ pip install theano

Console/Terminal Output

~$ pip install theano
Collecting theano
  Downloading Theano-1.0.1.tar.gz (2.8MB)
    100% |????????????????????????????????| 2.8MB 224kB/s 
Requirement already satisfied: numpy>=1.9.1 in ./lib/python3.6/site-packages (from theano)
Collecting scipy>=0.14 (from theano)
  Downloading scipy-1.0.0-cp27-cp27mu-manylinux1_x86_64.whl (46.7MB)
    100% |????????????????????????????????| 46.7MB 19kB/s 
Requirement already satisfied: six>=1.9.0 in ./lib/python3.6/site-packages (from theano)
Installing collected packages: scipy, theano
  Running setup.py install for theano ... done
Successfully installed scipy-1.0.0 theano-1.0.1

After installation, check the installed package details with the following command.

</>
Copy
pip show Theano

Verify Theano Installation in Ubuntu

The simplest verification is to import Theano from Python and print its version.

</>
Copy
python -c "import theano; print(theano.__version__)"

If Theano is installed correctly, the command prints the installed Theano version without an import error.

You can also run a small Theano expression to confirm that symbolic variables and compiled functions are working.

</>
Copy
import theano
import theano.tensor as T

x = T.dscalar('x')
y = T.dscalar('y')
z = x + y

add = theano.function([x, y], z)
print(add(10, 20))

The expected output is:

30.0

Install Theano Dependencies on Ubuntu

Theano depends on NumPy, SciPy, and six. In most Anaconda environments, NumPy is already available. If any dependency is missing, install or update the required packages with pip.

</>
Copy
pip install numpy scipy six

For a conda-based setup, you may also install these dependencies using conda before installing Theano.

</>
Copy
conda install numpy scipy six

Common Theano Installation Issues in Ubuntu

If Theano does not import after installation, check these common causes first.

  • Wrong Python environment: Activate the same conda environment where you installed Theano.
  • pip points to system Python: Use python -m pip install theano inside the active environment.
  • Dependency mismatch: Install compatible versions of NumPy and SciPy in the same environment.
  • Compiler-related errors: Install basic build tools if Theano tries to compile extensions on your system.
</>
Copy
sudo apt update
sudo apt install build-essential

If you are using a newer Ubuntu or Python version and the original Theano package fails, create an older isolated environment for the tutorial or legacy project instead of changing your global Python setup.

CPU and GPU Notes for Theano on Ubuntu

The basic installation shown above is enough for CPU-based Theano examples. GPU configuration is more involved because it depends on the CUDA toolkit, NVIDIA driver version, and compatible Python package versions. If you only want to learn Theano syntax or run small examples, start with the CPU setup first.

For a CPU-only test, the verification example in this tutorial is sufficient. Configure GPU support only when a specific project requires it and when the CUDA version required by that project is clear.

When to Use Theano for Deep Learning Today

Theano is useful when you are learning from older deep learning tutorials, reproducing academic examples, or maintaining existing code that already uses Theano. For a new production project, evaluate current deep learning libraries before deciding on Theano, because the Python machine learning ecosystem has changed significantly since Theano was widely used.

FAQs on Installing Theano Python Library in Ubuntu

How to install Theano in Python on Ubuntu?

Create and activate a conda environment, then run pip install theano. After installation, verify it with python -c "import theano; print(theano.__version__)".

Should I install Theano globally or inside a virtual environment?

Install Theano inside a conda environment or virtual environment. This keeps older Theano dependencies separate from other Python projects on your Ubuntu system.

Why does Theano installation fail on a newer Python version?

The original Theano package is commonly used with older Python and scientific package versions. If installation fails on a newer Python version, create a separate environment with an older compatible Python version and install NumPy, SciPy, six, and Theano there.

How do I check whether Theano installed correctly?

Import Theano from Python and print its version. You can also run a small compiled function, such as adding two symbolic scalar values, to confirm that Theano is working.

Is Theano still the best Python library for deep learning?

Theano is mainly useful for legacy deep learning code and older tutorials. For new deep learning projects, compare current libraries such as TensorFlow and PyTorch before choosing a framework.

QA Checklist for This Theano Ubuntu Installation Tutorial

  • Confirm that all commands are intended for Ubuntu terminal usage.
  • Check that the Anaconda prerequisite link is retained and unchanged.
  • Ensure the original installation command and original terminal output block remain unchanged.
  • Verify that new command-line examples use the language-bash class.
  • Verify that the Python verification example uses the language-python class and output-only blocks use the output class.
  • Make sure the article clearly explains that Theano is mainly useful for legacy or learning workflows.

Conclusion

Theano Python Library is successfully installed when the package imports without errors and a small symbolic expression runs correctly. For a clean Ubuntu setup, use Anaconda, keep Theano in a separate environment, install the required dependencies, and verify the installation before running larger deep learning examples.