Set Up a Virtual Environment in Python

The key to managing project dependencies without conflicts. Here's how to create and use a virtual environment in Python:

  1. Install venv, Python's built-in virtual environment tool (if not already installed).
  2. Create a new virtual environment for your project.
  3. Activate the virtual environment to isolate your project dependencies.
  4. Deactivate the virtual environment when you're done working on the project.

Pro tip: Always activate the virtual environment before installing packages with pip to keep dependencies isolated per project.

What You Need

Python 3.10

Ensure you have Python 3.10 or later installed to use venv.

PyCharm

An optional IDE that simplifies managing virtual environments and dependencies.

Visual Studio Code

Another optional IDE with extensions to manage virtual environments.

pip

Python's package installer, essential for installing packages within the virtual environment.

This page contains affiliate links. If you purchase through these links, we may earn a commission at no extra cost to you. Learn more.

Ask Pyflo anything →