How to install Theano on Linux

Theano is an open open-source library in Python for numerical computation that helps in optimizing and evaluating mathematical expressions containing multi-dimensional arrays. Theano was developed for researchers to conduct deep learning, computer vision, and natural language processing experiments. We can install Theano on Windows, Linux, and MacOS. In this Answer, we will discuss how to do that on Linux.

Dependencies to install Theano

Installing Linux requires some dependencies to be resolved. First, we will install those dependencies on the system and then move toward the installation of Theano.

  • Theano requires Python to be installed on the system. Make sure to install Python 3. After that, you can check the version of Python through the following command.

python3 --version
Python version
  • Theano library depends upon the NumPy library for the numerical computation of multi-dimensional arrays. Run the below command in the Linux terminal to install the NumPy library.

pip3 install numpy
Install NumPy
  • SciPy is not strictly required for Theano, but it is beneficial for scientific computation tasks.

pip3 install scipy
Install SciPy
  • Theano can use optimized BLAS and LAPACK libraries to speed up certain numerical computations. While not mandatory, using these libraries is recommended for better performance.

sudo apt-get install libblas-dev liblapack-dev
Install BLAS and LAPACK

After installing all these required libraries, the system is ready for the installation of Theano.

Install Theano

We are just one command away from installing Theano on Linux. That command is given below

pip3 install Theano
Install Theano

As we run the command, we will be able to install Theano on Linux.

Theano installed on Linux
Theano installed on Linux

Theano code

Now, we are going towards how to run Theano code on Linux. Look at the simple code below in which we are adding two numbers.

import theano
import theano.tensor as T
# Define symbolic variables
x = T.scalar('x')
y = T.scalar('y')
z = x + y
# Create a Theano function
add = theano.function(inputs=[x, y], outputs=z)
# Call the function with inputs 3 and 5
result = add(3, 5)
print("Addition : ",result) # Output: 8

The name of the file in which this code is present is "Theano.py". To code present in the file can be run through the following command in a Linux terminal.

python3 Theano.py
Command to run the code

The result of the code is:

Conclusion

Theano is an open-source library for numerical computation in Python. To install it on Linux, you need to resolve some dependencies, including Python 3, NumPy, and optionally SciPy, as well as optimized BLAS and LAPACK libraries for better performance. Once the dependencies are installed, you can use pip to install Theano. This Answer also illustrates how you can run the code through a Linux terminal.

Q

Which library does Theano rely on for numerical computations with multi-dimensional arrays?

A)

NumPy

B)

SciPy

C)

Pandas

D)

Matplotlib

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved