*ARGS.TECH | BLOG | How to use Python virtual environments (venv): A beginner's guide
Loading...
BLOG
How to use Python virtual environments (venv): A beginner's guide
Terminal: ~

# A simple, step-by-step cheatsheet to creating, activating, and managing Python

# virtual environments with venv. This guide also educate you how to install PIP packages

# in your virtual environment. Perfect for beginners on Linux, macOS, and Windows.


# ----- Python Virtual Environments (venv) -----


# 1. Install the venv package.

# On Debian/Ubuntu, you may need to install it separately:

xinit@localhost:~$ sudo apt install python3-venv

# On Windows and other systems, the venv module is included with Python 3 by default.


# 2. Create & navigate in project directory:

xinit@localhost:~$ mkdir myproject && cd myproject


# 3. Create the environment (e.g., named 'env'):

xinit@localhost:~/myproject$ python3 -m venv env


# 4. Activate the environment.

# On Linux/macOS (bash/zsh):

xinit@localhost:~/myproject$ source env/bin/activate

# On Windows (Command Prompt):

xinit@localhost:~/myproject$ env\Scripts\activate.bat

# Your terminal prompt will now change:

(env) xinit@localhost:~/myproject$ python -V


# 5. Install some package in your virtual environment. Django for example:

(env) xinit@localhost:~/myproject$ pip install django


# 6. Leave the environment:

(env) xinit@localhost:~/myproject$ deactivate


# Pro-Tip: Always add your venv folder ('env/') to your .gitignore file!

www.args.tech
Top button
© *ARGS.TECH
2025
v 2.6.19