Python is a versatile, high-level programming language that has become indispensable in numerous fields, including the burgeoning world of drones and advanced flight technology. Its extensive libraries and frameworks make it ideal for developing sophisticated applications for flight control, data analysis, autonomous navigation, and even image processing from aerial platforms. For enthusiasts and professionals working with drones, understanding how to install and manage Python on an Ubuntu operating system is a fundamental skill. Ubuntu, a popular Linux distribution, provides a robust and flexible environment for Python development, offering a wide array of tools and excellent community support.

This guide will walk you through the process of installing Python on Ubuntu, ensuring you have a stable and up-to-date environment ready for your drone-related projects. We will cover different installation methods, package management, and best practices for maintaining your Python setup.
Understanding Python Versions on Ubuntu
Ubuntu, like many Linux distributions, often comes with Python pre-installed. However, the version included might not always be the latest or the specific version required for your particular drone software or development needs. It’s crucial to understand that multiple Python versions can coexist on a single system, and managing them effectively is key to avoiding conflicts and ensuring your projects run as expected.
Default Python Installation
When you first install Ubuntu, a system Python interpreter is usually present. This is often Python 2 (though newer Ubuntu versions are increasingly defaulting to Python 3). This system Python is critical for many operating system functions and scripts. Therefore, it’s strongly discouraged to alter or remove the system’s default Python installation. Instead, the best practice is to install additional, newer versions of Python alongside the system version and manage them using dedicated tools.
Python 2 vs. Python 3
Python 2 reached its official end-of-life in January 2020. While some legacy systems might still rely on it, all new development should prioritize Python 3. Python 3 offers numerous improvements, syntax enhancements, and bug fixes that make it a more powerful and future-proof choice. When installing Python on Ubuntu for drone development, it’s highly recommended to install and use Python 3.
Checking Installed Python Versions
Before proceeding with any installation, it’s wise to check which Python versions are already present on your system. You can do this by opening a terminal window (usually by pressing Ctrl+Alt+T) and running the following commands:
python --version
python2 --version
python3 --version
The python --version command will typically point to the default Python interpreter linked to the python command. If you have multiple Python 3 versions installed, you might need to specify them, for example, python3.9 --version or python3.10 --version, if they have been installed as separate executables.
Installing Python 3 Using Ubuntu’s Package Manager (APT)
The most straightforward and recommended method for installing Python 3 on Ubuntu is by using the Advanced Packaging Tool (APT), Ubuntu’s default package manager. APT handles downloading, installing, and managing software packages efficiently.
Updating Package Lists
Before installing any new software, it’s a good practice to update your system’s package lists. This ensures that you are getting the latest available versions of packages and their dependencies. Open your terminal and run:
sudo apt update
This command downloads the latest package information from the repositories configured on your system.
Installing the Latest Python 3 Version
To install the latest stable version of Python 3 available in Ubuntu’s official repositories, use the following command:
sudo apt install python3
This command will install Python 3 and its essential libraries. If you need the pip package installer (which is crucial for installing Python libraries), you should also install it using APT:
sudo apt install python3-pip
pip is the de facto standard package manager for Python. It allows you to easily install and manage third-party libraries and frameworks that are essential for drone development, such as NumPy, SciPy, OpenCV, and specific libraries for drone SDKs.
Installing Specific Python 3 Versions
Ubuntu’s repositories may not always contain the very latest Python release immediately upon its official launch. However, they usually offer recent and well-supported versions. If you need a specific version not directly available via apt install python3, you might need to explore other methods or consider using a PPA (Personal Package Archive).
For instance, if a specific drone SDK requires Python 3.9 and your system defaults to 3.8, you might install 3.9 like this (assuming a PPA that provides it is added):
First, add a PPA that offers newer Python versions. A commonly used one is the deadsnakes PPA.
sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
Then, you can install a specific version, for example, Python 3.9:
sudo apt install python3.9 python3.9-venv python3.9-dev
It’s also recommended to install the corresponding pip for this specific version. Often, installing the python3.x-venv package will also provide the correct pip for that version.
Verifying the Installation
After the installation is complete, you can verify that Python 3 and pip are installed correctly:
python3 --version
pip3 --version

You should see the installed Python 3 version number and the pip version number printed in the terminal.
Managing Python Environments with venv
When working on multiple drone projects, you’ll likely encounter situations where different projects require different versions of Python or different sets of libraries. Installing all these dependencies globally can lead to conflicts and make it difficult to manage your project’s requirements. This is where virtual environments come into play.
Python’s built-in venv module provides a way to create isolated Python environments. Each virtual environment can have its own Python interpreter and its own set of installed packages, completely independent of other environments and the system’s global Python installation. This is particularly useful for drone development where specific SDKs might have strict dependency requirements.
Creating a Virtual Environment
To create a virtual environment, first, navigate to your project’s directory in the terminal. Then, use the venv module to create the environment. It’s common to name the virtual environment directory .venv or venv.
# Navigate to your project directory
cd /path/to/your/drone/project
# Create a virtual environment using your installed Python 3
python3 -m venv venv
This command will create a venv directory within your project folder. Inside this directory, you’ll find the Python interpreter, standard libraries, and the pip executable for this specific environment.
Activating a Virtual Environment
Before you can use a virtual environment, you need to activate it. Activating an environment modifies your shell’s PATH to prioritize the Python interpreter and scripts within the virtual environment.
To activate the environment, run:
source venv/bin/activate
Once activated, your terminal prompt will typically change to indicate that you are inside the virtual environment, often by prepending the environment’s name in parentheses, like (venv) user@hostname:~/your/drone/project$.
Installing Packages within a Virtual Environment
With the virtual environment activated, any pip commands you run will install packages into that specific environment, not globally.
pip install numpy scipy opencv-python
This command installs NumPy, SciPy, and OpenCV into your active venv. These packages will be available only when this virtual environment is activated.
Deactivating a Virtual Environment
When you’re finished working on your project or want to switch to another environment, you can deactivate the current one by simply typing:
deactivate
The prompt will return to its normal state, and your system’s global Python environment will be active again.
Installing Python via Source Compilation (Advanced)
While APT is the preferred method for most users, there are situations where you might need to compile Python from its source code. This is typically done when you require a very specific, cutting-edge version not yet available in any repository, or when you need to customize build options. Compiling from source provides the most control but is a more complex and time-consuming process.
Downloading Python Source Code
First, you’ll need to download the source tarball for the desired Python version from the official Python website (python.org).
# Example for Python 3.11.4
wget https://www.python.org/ftp/python/3.11.4/Python-3.11.4.tgz
tar -xf Python-3.11.4.tgz
cd Python-3.11.4
System Dependencies for Compilation
Before compiling, ensure you have the necessary build tools and development libraries installed. These are often available through APT.
sudo apt update
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev
Configuration and Compilation
The ./configure script prepares the build process. It’s crucial to use the --enable-optimizations flag, which runs the test suite twice to improve runtime performance. The --prefix flag allows you to specify an installation directory if you don’t want to install it in the default system location.
./configure --enable-optimizations --prefix=/usr/local/opt/python-3.11.4
make -j $(nproc)
sudo make altinstall
The make -j $(nproc) command uses all available CPU cores to speed up the compilation process. The sudo make altinstall command is vital. Unlike make install, altinstall avoids creating symlinks that could conflict with the system’s default Python installation (e.g., it won’t overwrite /usr/bin/python3). This ensures that you can have multiple Python versions installed without breaking system utilities.
After running altinstall, you can access your newly compiled Python by its specific version name, e.g., /usr/local/opt/python-3.11.4/bin/python3.11. You would then typically create a virtual environment using this specific interpreter.

Conclusion
Installing Python on Ubuntu is a foundational step for anyone venturing into drone technology, aerial robotics, and related fields. By understanding the nuances of Python versions, utilizing the APT package manager for straightforward installations, and mastering virtual environments with venv, you can create a robust and flexible development setup. Whether you are developing autonomous flight paths, processing aerial imagery, or integrating advanced sensor data, a well-managed Python environment on your Ubuntu system will be your most valuable asset. Always prioritize Python 3 for new projects and leverage virtual environments to keep your dependencies organized and avoid conflicts, ensuring a smooth and productive development workflow.
