Install GNU Radio in a Python Virtualenv: A Complete Guide (2026)

Discover how to install GNU Radio within a Python virtual environment using Python 3.9 on Ubuntu 20.04, keeping your system Python clean.

Install GNU Radio in a Python Virtualenv: A Complete Guide (2026)

GNU Radio is a powerful toolkit for building software-defined radios and signal-processing systems. For developers looking to keep their systems clean and manage dependencies effectively, installing GNU Radio within a Python virtual environment is a wise choice. This guide will walk you through the steps to achieve this setup on Ubuntu 20.04.4 LTS, allowing you to use Python 3.9 while keeping your system's Python 3.8 intact.

Key Takeaways

  • Learn to install GNU Radio in a Python virtual environment on Ubuntu 20.04.4 LTS.
  • Understand how to resolve common issues with system and virtual environment dependencies.
  • Use Python 3.9 while maintaining a clean system Python 3.8 installation.
  • Get troubleshooting tips for common installation errors.

Installing software in a virtual environment is beneficial for maintaining an organized development space, especially when dealing with different Python versions or dependencies. By the end of this tutorial, you'll have a fully functional GNU Radio installation within a virtual environment, configured for Python 3.9, and understand how to troubleshoot common issues.

Prerequisites

  • Ubuntu 20.04.4 LTS operating system
  • Basic knowledge of terminal commands
  • Python 3.9 installed on your system
  • Virtualenv package installed

Step 1: Install Python 3.9

First, ensure that Python 3.9 is installed on your system. You can check this by running:

python3.9 --version

If Python 3.9 is not installed, add the deadsnakes PPA and install it:

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.9 python3.9-venv python3.9-dev

Step 2: Create a Python Virtual Environment

Create a new directory for your project and navigate into it. Then create a Python 3.9 virtual environment:

mkdir gnuradio_project
cd gnuradio_project
python3.9 -m venv venv

Activate the virtual environment:

source venv/bin/activate

Step 3: Install Dependencies

Before installing GNU Radio, you need to install some necessary dependencies. Inside your virtual environment, run:

pip install cmake
pip install numpy scipy

Step 4: Install GNU Radio

Now, install GNU Radio using pip within your virtual environment:

pip install gnuradio

This command installs GNU Radio and all its Python dependencies in your virtual environment.

Step 5: Verify the Installation

To ensure that GNU Radio has been installed correctly, try importing it in the Python shell:

python
>>> import gnuradio
>>> print(gnuradio.__version__)

If no errors occur and the version prints correctly, you have successfully installed GNU Radio in your virtual environment.

Common Errors/Troubleshooting

  • ImportError: If you encounter an import error, ensure that the virtual environment is activated and all dependencies are properly installed.
  • Version Conflicts: If you have version conflicts, ensure that the virtual environment is using Python 3.9 and not the system Python 3.8.
  • Missing Dependencies: Some dependencies might be missing. Check the error message for clues and install any additional packages as needed.

Conclusion

By following these steps, you have installed GNU Radio in a Python virtual environment, maintaining a clean and organized development setup. This configuration allows you to leverage Python 3.9 for your projects while keeping your system Python intact. If you encounter any issues, refer to the troubleshooting section to resolve common problems.

Frequently Asked Questions

Can I use a different version of Python?

Yes, you can use any version of Python installed on your system, but ensure compatibility with GNU Radio.

Why use a virtual environment?

A virtual environment helps manage project-specific dependencies and avoids cluttering the system Python installation.

What if I encounter installation errors?

Check for missing dependencies or version conflicts, and refer to the troubleshooting section for common solutions.

Is it necessary to use pip for all installations?

Using pip within the virtual environment ensures that all dependencies are installed in the correct location.