Fundamentals 5 min read

How to Create and Manage Python Virtual Environments on Ubuntu 14.04

This guide walks you through installing virtualenv on Ubuntu 14.04, creating separate Python 2 and Python 3 virtual environments, activating and deactivating them, and verifying the active interpreter, all with clear step‑by‑step commands and screenshots.

Python Crawling & Data Mining
Python Crawling & Data Mining
Python Crawling & Data Mining
How to Create and Manage Python Virtual Environments on Ubuntu 14.04

Installing Python on Ubuntu 14.04 is straightforward using apt‑get, and this article focuses on setting up Python virtual environments.

1. Install virtualenv

Run the command: sudo pip install virtualenv If this fails, use the alternative: sudo apt‑get install python‑virtualenv After installation, verify with: pip list Images below illustrate the installation process.

2. Create a virtual environment

Navigate to the desired directory and run:

virtualenv demo

3. Activate the environment

Enter the environment’s bin directory and activate it:

source activate

After activation, running python starts the Python 3 interpreter.

4. Create a Python 2 virtual environment

Run:

virtualenv -p /usr/bin/python2 py2

Activate it similarly:

source activate

Before switching, deactivate the current environment with:

deactivate

5. Verify the interpreter

Inside the py2 environment, running python launches Python 2.

6. Exit the environment

Simply run:

deactivate

Now you can freely create and switch between Python virtual environments on Ubuntu.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Ubuntupython2python3virtualenv
Python Crawling & Data Mining
Written by

Python Crawling & Data Mining

Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.