How to set up a virtual environment for Python

This blog post is a small cheat sheet on setting up a virtual environment for Python venv.

Note: The virtual environment installation.

python3 -m pip install --user virtualenv

Step 1: Create a virtual environment

python3.11 -m venv my-env-3.11

When you look into your current folder, you will notice that the execution of this command created a new folder called my-env-3.11.

my-env-3.11
|-bin
|-include
|-lib
pyvenv.cfg

Step 2: Activate the environment

source ./my-env-3.11/bin/activate

Step 3: Install your project-related requirements

python3 -m pip install -r requirements.txt

Step 3: Deactivate the virtual environment

deactivate

I hope this was useful to you, and let’s see what’s next?

Greetings,

Thomas

#python, #venv, #cheatsheet

One thought on “How to set up a virtual environment for Python

Add yours

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Blog at WordPress.com.

Up ↑

%d bloggers like this: