A Python Virtual Environment for AI Tools on Ubuntu 24.04 LTS (AMD GPU)

If you have a PC with an AMD GPU and Ubuntu 24.04 LTS OS running, keep reading. In this article, I explain how to create a virtual environment with Python so that it can be used for most AI tooling on Ubuntu 24.04 LTS.
A virtual environment can be used to isolate Python packages from the Python installation running on the OS. Run the next steps to get the preparations done.
Before running the commands below, make sure to follow this article on how to install older versions of Python.
Ready? Then follow the steps below.
Installation
- Open a terminal by pressing the Windows button. Then type ‘cmd’ and press Enter. Go to the home directory of the logged user:
cd ~
- Create a folder by running the command:
mkdir ai-venv
- Go into the folder by running:
cd ai-venv
- Create the venv by running:
python3.10 -m venv venv
- Activate the venv:
source venv/bin/activate
- Upgrade the packages pip, setuptools, and wheel:
pip install --upgrade pip setuptools wheel
Now the virtual environment is ready. Go to pytorch.org and scroll down to 'Install PyTorch'. Select 'Stable', 'Linux', 'Pip', 'Rocm' and run the pip command that is shown on the website:
For example:
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm6.3
The command above can take a while, so you could take some coffee...
Run the command below to see if the torch
packages are listed:
pip list
This virtual environment can be used for multiple AI tools like image generation tools Stable Diffusion, Fooocus, ComfyUI, and more.
Member discussion