RackNerd Billboard Banner

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 --version

If you don’t see a version number, install Python:

sudo apt update
sudo apt install python3

Step 2: Install pip (If Needed)

pip is Python’s package manager. Confirm it’s installed:

pip3 --version

If not, install it:

sudo apt install python3-pip

Step 3: Install the venv Module

The venv module is included with Python 3.3 and above, but double-check:

sudo apt install python3-venv

Step 4: Create Your Virtual Environment

Navigate to your project directory, or make one:

mkdir myproject
cd myproject

Then create the environment:

python3 -m venv venv

This will create a new folder called venv in your project.

Step 5: Activate the Virtual Environment

Run:

source venv/bin/activate

Your 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 flask

Step 7: Deactivate When Done

To leave the virtual environment, just run:

deactivate

Why 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!

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
RackNerd Billboard Banner
© 2025 Computer Everywhere
Your Everyday Guide to the Digital World.
Terms of Service | Privacy Policy
Copy link