Introduction: How to Setup and Configure Python VENV Virtual Environment on Ubuntu Linux
In this Instructable, you’ll learn exactly how to install, create, activate, and manage a Python virtual environment on Ubuntu Linux (Ubuntu 25.10),even if you’re new to the process of creating virtual environment.
We’ll walk through each step ensuring you can easily set up your development workspace without breaking system-wide packages or running into version issues.
Setting up a dedicated Python virtual environment is one of the most important first steps for any developer working on Ubuntu Linux. Whether you’re building web applications, automating tasks, experimenting with libraries, or managing multiple projects, using Python’s built-in venv module helps you keep your dependencies clean, isolated, and conflict-free
Supplies
- A Linux computer (Ubuntu 25.10) with a Python Interpreter Installed
- Text Editor
- Internet Connection
This is a Software Project ,So most of the things are already present in the Linux computer
Step 1: Creating a Python VENV Virtual Environment on Linux
A short Intro to Python Virtual Environments
A Python virtual environment is a self-contained directory that includes its own Python interpreter, essential activation scripts, and isolated installed libraries, keeping it completely separate from the system's main Python installation. This crucial isolation ensures you can work on diverse projects, even those requiring different dependency versions or configurations, without creating conflicts, thereby preventing accidental interference with the core system environment upon which other programs may rely.
There are multiple ways to create Python Virtual Environments on Linux like
- venv
- virtualenv
- conda,
- pipenv,
- poetry.
The venv module, which is built into standard Python, is a particularly useful tool for creating these environments on various platforms, including both Windows and Linux, and is especially valuable on embedded systems like the Raspberry Pi.
On the Raspberry Pi, a virtual environment is commonly used when developing Python-based software, such as a data acquisition system or a embedded web server using flask , as it allows developers to install project-specific modules without needing administrative rights and guarantees that the project's dependencies remain stable and separate from the operating system's packages.
Creating a Python VENV Virtual Environment on Linux

In this Instructable, we will be concentrating on the VENV Module on Linux Systems mainly Debian Based Systems like Ubuntu ,Linux Mint etc .
Here we will be using the Ubuntu 25.10 Version Latest one that is available.
Ensure a Python interpreter is installed on your system; it's typically pre-installed on most Linux distributions. To verify its location, you can use the which python command, which will display the path to the Python executable.

Your system Python is usually located at /usr/bin/python3
You can now create a Python virtual environment using the venv module by issuing the below command.
Here, my_venv is the name we've chosen for our virtual environment. If the command runs successfully, a new directory named my_venv will be created to house all your local files and modules. You are free to choose any name you prefer instead of my_venv.
Step 2: Resolving the Ensurepip Is Not Available Error on Linux
The "ensurepip is not available" error typically occurs when the version of Python you are using was compiled without the built-in ensurepip module. This module is what allows you to bootstrap pip (Python's package installer) into a fresh Python installation or virtual environment.
So we need to install ensurepip using apt. just copy the command from the error message and run it.

Step 3: How Python VENV Virtual Environment Is Structured on Linux
When you create a virtual environment in Python using venv, it isn't just a folder for your code; it's a clever redirection of the Python interpreter. On Linux, this structure follows a specific hierarchy to isolate your project's dependencies from the system's global Python installation.
python3 -m venv my_venv
Here is how a standard VENV virtual environment is organized.
The top-level folder my_venv contains the entire environment. It is self-contained, meaning you can delete this folder to completely uninstall the environment without affecting your system.
/bin directory
The /bin directory acts as the engine of a Linux-based virtual environment, serving a purpose similar to the /Scripts folder in Windows. This critical directory contains the local tools necessary to manage the environment, including python and python3, which are symlinks (shortcuts) that point back to the specific system Python executable used during creation. It also houses local package managers like pip and pip3, ensuring that installations remain isolated. To engage the environment, the folder includes the activate shell script along with versions for alternative shells like activate.csh and activate.fish which updates the terminal's $PATH so that commands default to these local versions rather than the global system files.
/lib directory
The /lib directory is the heart of a virtual environment's isolation, housing a specific python3.x/site-packages/ subdirectory where all local dependencies are stored. Whenever you use pip install to add libraries like Pandas, Django, or Flask, they are saved directly into this folder rather than the global system space. When the environment is active, Python automatically prioritizes this local path in its search hierarchy allowing it to use these specific versions while effectively ignoring globally installed libraries that might otherwise cause version conflicts.
/include directory
While usually empty upon creation, the include/ directory plays a vital role in supporting complex Python packages that rely on C extensions. It serves as a storage location for C header files required during the installation and compilation process of libraries like NumPy or cryptography. By providing this dedicated space, the virtual environment ensures that the compiler can access the necessary definitions to build these high-performance components locally without interfering with the headers of the main operating system.
pyvenv.cfg file
The pyvenv.cfg file acts as the configuration hub for the virtual environment, providing the Python interpreter with essential instructions on how to behave. Located in the root directory, this small text file defines the home path to the system Python binary and identifies the specific version of Python in use. Crucially, it includes the include-system-site-packages setting, a boolean value that determines whether the environment remains strictly isolated or is allowed to access the global library collection

How Python VENV Virtual Environment works on Linux
The magic of virtual environment isolation lies in environment variables rather than moving physical files. When you run the activate script, it primarily prepends the environment's /bin directory to your shell's $PATH, ensuring that the local version of Python is discovered first, and sets a VIRTUAL_ENV variable that directs the interpreter to the pyvenv.cfg file for its library roots. Interestingly, formal activation is actually optional; you can achieve the same isolated execution by calling the environment’s Python binary directly via its absolute path (e.g., ./myenv/bin/python script.py), which automatically triggers the environment's internal logic to use its local libraries.
Step 4: Activating Python Virtual Environments (venv) on Linux
Activating a Python virtual environment on Linux is primarily handled through the source command, which executes a shell script within your current terminal session to modify your environment variables.
When you run source /bin/activate, the script prepends the virtual environment’s /bin directory to your system's $PATH, ensuring that the python and pip commands point to the isolated versions inside the folder rather than the global system versions.

This process also sets a VIRTUAL_ENV environment variable and typically modifies your shell prompt (PS1) to display the name of the environment in parentheses, providing a visual cue that isolation is active.
Step 5: DeActivating Python Virtual Environments (venv) on Linux
To exit a Python virtual environment on Linux, you use a single command called deactivate that is built into the shell's current session during the activation process.
This command works because the activate script you ran earlier creates a shell function named deactivate. This function is stored in your terminal's memory and is designed to undo the changes made during activation.
Step 6: Installing Modules Inside a Python Venv on Linux
To install modules inside a Python virtual environment on Linux, you must first establish a structured project directory and initialize the environment itself. By running the following commands, you set up a clean workspace and a dedicated isolation layer for your dependencies
Once this structure is in place, you must activate the environment using source venv/bin/activate.
From that point forward, any modules installed via pip install (such as requests or numpy) will be confined to the local venv/lib/ directory. This ensures your project remains portable and prevents "dependency hell," where different projects require conflicting versions of the same library. By keeping your source code in src/ and your environment in /venv, you maintain a professional, organized workflow that separates your logic from your dependencies.
To install packages within your virtual environment, you must first ensure it is active so that your libraries are correctly routed to the local venv/lib/python3.x/site-packages directory.
Once activated, your terminal prompt will typically show (venv) as a prefix, indicating that any installations will remain isolated from the global system. You can then use the package manager to install specific libraries, such as ttkbootstrap, by running the following command
Using python3 -m pip is the recommended best practice as it ensures you are using the specific pip instance tied to that Python version. After the installation finishes, the ttkbootstrap library along with all its necessary dependencies will be neatly contained within your environment's folders, ready for you to import into your scripts located in the /src directory.

After this you can find the package inside the site-packages directory as shown below.






