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.
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 demo3. Activate the environment
Enter the environment’s bin directory and activate it:
source activateAfter activation, running python starts the Python 3 interpreter.
4. Create a Python 2 virtual environment
Run:
virtualenv -p /usr/bin/python2 py2Activate it similarly:
source activateBefore switching, deactivate the current environment with:
deactivate5. Verify the interpreter
Inside the py2 environment, running python launches Python 2.
6. Exit the environment
Simply run:
deactivateNow you can freely create and switch between Python virtual environments on Ubuntu.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
