Ubuntu ships with Python, but not the version you want for AI work. You need Python 3.11 or 3.12, plus the right package management setup. The system Python is for Ubuntu's own programs. Leave it alone.
Install Python the right way
Open the terminal with Ctrl+Alt+T. First, add the deadsnakes repository. This gives you access to newer Python versions without waiting for Ubuntu's slow update cycle.
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
Now install Python 3.12 and the development tools you need:
sudo apt install python3.12 python3.12-venv python3.12-dev
The python3.12-dev package includes headers that some AI libraries need to compile properly. Skip it and you'll hit cryptic build errors later.
Check your installation:
python3.12 --version
You should see Python 3.12.x. Good. Now make Python 3.12 your default by creating an alias. Add this line to your ~/.bashrc file:
echo "alias python=python3.12" >> ~/.bashrc
source ~/.bashrc
Set up pip and virtual environments
Install pip for your Python version:
python -m ensurepip --upgrade
Now install the tools that make Python development sane:
python -m pip install --upgrade pip
python -m pip install virtualenv
Create your first AI environment
Never install AI packages globally. They have conflicting dependencies and you'll create a mess that's hard to untangle. Virtual environments solve this.
Create a virtual environment for your AI work:
python -m venv ~/ai-env
source ~/ai-env/bin/activate
Your terminal prompt should now show (ai-env) at the beginning. This means you're inside the virtual environment. Anything you install with pip goes here, not into the system Python.
To activate this environment in future sessions:
source ~/ai-env/bin/activate
To leave the environment:
deactivate
Install core AI libraries
With your virtual environment active, install the core libraries. Start with NumPy and pandas:
pip install numpy pandas
NumPy handles arrays and mathematical operations. Pandas manages data in tables and spreadsheets. Every AI project uses both.
Add matplotlib for plotting:
pip install matplotlib
Now install scikit-learn for traditional machine learning:
pip install scikit-learn
Test your installation. Start Python and import each library:
python
>>> import numpy as np
>>> import pandas as pd
>>> import matplotlib.pyplot as plt
>>> import sklearn
>>> print("Everything works")
>>> exit()
If any import fails, something went wrong. The error message will tell you what's missing.
Add Jupyter for interactive work
Jupyter notebooks let you write code, see results, and document your thinking in one place. Essential for data exploration and experimentation.
pip install jupyter
Start Jupyter:
jupyter notebook
Your web browser opens with the Jupyter interface. Create a new notebook and run a simple test:
import numpy as np
import pandas as pd
data = np.array([1, 2, 3, 4, 5])
df = pd.DataFrame({'numbers': data, 'squares': data**2})
print(df)
You should see a table with numbers and their squares. Jupyter is working.
Stop Jupyter by pressing Ctrl+C in the terminal, then y to confirm.
Why this setup works
This approach separates your AI work from the system. Ubuntu updates won't break your projects. You can have multiple environments for different projects with different library versions. When something breaks, you delete the environment and start fresh instead of debugging a tangled system installation.
The virtual environment lives in your home directory. Your projects, notebooks, and data stay safe even if you recreate the environment. This is how professional developers work, and now you do too.