aster.cloud aster.cloud
  • /
  • Platforms
    • Public Cloud
    • On-Premise
    • Hybrid Cloud
    • Data
  • Architecture
    • Design
    • Solutions
    • Enterprise
  • Engineering
    • Automation
    • Software Engineering
    • Project Management
    • DevOps
  • Programming
  • Tools
  • About
aster.cloud aster.cloud
  • /
  • Platforms
    • Public Cloud
    • On-Premise
    • Hybrid Cloud
    • Data
  • Architecture
    • Design
    • Solutions
    • Enterprise
  • Engineering
    • Automation
    • Software Engineering
    • Project Management
    • DevOps
  • Programming
  • Tools
  • About
  • DevOps
  • Programming

How To: Configure Python Virtual Environment In Ubuntu

  • root
  • April 6, 2019
  • 2 minute read

Overview

This guide/article shows how to install, configure/create and use a Python Virtual environment.

Prerequisites

  • Operating System: Ubuntu 16 or greater
  • Python is installed. Python 3.X or 2.X.

Steps

Check that Python is available on the system. The Python version should be returned.

# If Python 2.x
$ python --version

# If Python 3.x
$ python3 --version

For the next steps, we will be using Python 3.7 for the sample, but should still be usable for Python 2.X.

01. Install Python Pip. Pip is a package manager for Python.

$ sudo apt-get update
$ sudo apt-get install python3-pip -y

 

02. Verify that Pip has been installed.

$ pip3 --version

 

03. Install the Python Virtual environment

$ sudo apt-get install python3-venv

 

04. Navigate to the directory on where to create the Virtual environment. In this example, we will be creating the virtual environment on the HOME directory.

$ cd ~

# FORMAT
$ python3 -m venv

# SAMPLE
$ python3 -m venv dotlah-python-venv

 

Note that this command will create a Virtual Environment that uses the current version of Python. Which is Python 3.7 in this example.

 

05. Activate the virtual environment.

$ cd ~
$ source dotlah-python-venv/bin/activate

 

06. If the terminal or shell has been prepend with the name of the virtual environment. Then the Virtual environment has been activated successfully.

 

Advantages

“Python applications will often use packages and modules that don’t come as part of the standard library. Applications will sometimes need a specific version of a library, because the application may require that a particular bug has been fixed or the application may be written using an obsolete version of the library’s interface.”

— https://docs.python.org

— Virtual environment helps isolate the dependencies of different projects separate from each other

Read More  How To Migrate A Group Of Individual Instances To A Stateful MIG Using Python Script

— Different applications can use different virtual environments with different python packages or libraries

— Different virtual environments can also be used for testing different versions of a Python package. Example is when migrating or upgrading from a lower version to a newer version. Checking if there will be incompatibilities with new version.

root

Related Topics
  • How To
  • Programming
  • Python
  • Ubuntu
You May Also Like
View Post
  • DevOps
  • Engineering

Verify POST Endpoint Availability With Uptime Checks

  • March 24, 2023
View Post
  • Automation
  • Programming

Learn Expect By Writing And Automating A Simple Game

  • March 14, 2023
View Post
  • Automation
  • Computing
  • DevOps

The Good And Bad Of ‘Zero-Touch’ Cloud Operations

  • February 23, 2023
View Post
  • DevOps
  • Software Engineering
  • Tools

Are Your CICD And DevOps Tools Really Helping Developers?

  • February 22, 2023
SQL
View Post
  • Data
  • Programming

Infrastructure from Code: the New Wave of Cloud Infrastructure Management

  • February 16, 2023
View Post
  • DevOps

How Multicloud Changes DevOps

  • February 15, 2023
View Post
  • Programming

Go 1.20 Is Released!

  • February 13, 2023
View Post
  • Computing
  • Programming

Tiny Snippets Of Code That Changed The World

  • January 23, 2023

Stay Connected!
LATEST
  • 1
    How AI Can Improve Digital Security
    • March 27, 2023
  • 2
    Docker’s Bad Week
    • March 27, 2023
  • 3
    My First Pull Request At Age 14
    • March 24, 2023
  • 4
    AWS Chatbot Now Integrated Into Microsoft Teams
    • March 24, 2023
  • 5
    Verify POST Endpoint Availability With Uptime Checks
    • March 24, 2023
  • 6
    Sovereign Clouds Are Becoming A Big Deal Again
    • March 23, 2023
  • 7
    Ditching Google: The 3 Search Engines That Use AI To Give Results That Are Meaningful
    • March 23, 2023
  • 8
    Pythonic Techniques For Handling Sequences
    • March 21, 2023
  • 9
    Oracle Cloud Infrastructure to Increase the Reliability, Efficiency, and Simplicity of Large-Scale Kubernetes Environments at Reduced Costs
    • March 20, 2023
  • 10
    Monitor Kubernetes Cloud Costs With Open Source Tools
    • March 20, 2023
about
Hello World!

We are aster.cloud. We’re created by programmers for programmers.

Our site aims to provide guides, programming tips, reviews, and interesting materials for tech people and those who want to learn in general.

We would like to hear from you.

If you have any feedback, enquiries, or sponsorship request, kindly reach out to us at:

[email protected]
Most Popular
  • 1
    Cloudflare Takes On Online Fraud Detection Market
    • March 15, 2023
  • 2
    Linux Foundation Training & Certification & Cloud Native Computing Foundation Partner With Corise To Prepare 50,000 Professionals For The Certified Kubernetes Administrator Exam
    • March 16, 2023
  • 3
    Cloudflare Democratizes Post-Quantum Cryptography By Delivering It For Free, By Default
    • March 16, 2023
  • 4
    Daily QR “Scan Scams” Phishing Users On Their Mobile Devices
    • March 16, 2023
  • 5
    Lockheed Martin Launches Commercial Ground Control Software For Satellite Constellations
    • March 14, 2023
  • /
  • Platforms
  • Architecture
  • Engineering
  • Programming
  • Tools
  • About

Input your search keywords and press Enter.