Your cart is currently empty!
How to Create a Python Virtual Environment on Ubuntu
If you’re coding in Python on Ubuntu, using a virtual environment is non-negotiable. It keeps your projects organized and prevents dependency chaos. Here’s how to get your virtual environment up and running—no fluff, just steps.
Step 1: Make Sure Python Is Installed
Most Ubuntu versions come with Python pre-installed. To check, open your terminal and run:
python3 --versionIf you don’t see a version number, install Python:
sudo apt update
sudo apt install python3Step 2: Install pip (If Needed)
pip is Python’s package manager. Confirm it’s installed:
pip3 --versionIf not, install it:
sudo apt install python3-pipStep 3: Install the venv Module
The venv module is included with Python 3.3 and above, but double-check:
sudo apt install python3-venvStep 4: Create Your Virtual Environment
Navigate to your project directory, or make one:
mkdir myproject
cd myprojectThen create the environment:
python3 -m venv venvThis will create a new folder called venv in your project.
Step 5: Activate the Virtual Environment
Run:
source venv/bin/activateYour terminal prompt should now start with (venv). This means anything you install with pip will only affect this project.
Step 6: Install Your Packages
Now you’re free to install packages without messing up your system:
pip install requests flaskStep 7: Deactivate When Done
To leave the virtual environment, just run:
deactivateWhy Use a Virtual Environment?
- Isolation: Keeps project dependencies separate.
- No Admin Rights Needed: Install anything without sudo.
- Cleaner Workflow: Avoid “dependency hell” across projects.
Quick Reference
- Create venv:
python3 -m venv venv - Activate:
source venv/bin/activate - Deactivate:
deactivate
That’s it. Fast, simple, and headache-free Python development on Ubuntu.
Have questions or need help? Drop them in the comments!

Tech enthusiast and content creator passionate about making technology simple for everyone. I share practical tips, guides, and reviews on the latest in computers, software, and gadgets. Let’s explore the digital world together!
