DEV Community

Timo Reusch
Timo Reusch

Posted on

Create a Python virtual environment (quick)

When working with Python, it’s best practice to use a separate virtual environment for each project to avoid dependency conflicts. Tools like PyCharm create virtual environments automatically, but you can just as easily do it via the command line:

  1. cd to your project root and create a new virtual environment

    Running this command will create a .venv folder (a common name, but you can customize it if needed):

    python3 -m venv .venv
    
  2. Activate the virtual environment

    source .venv/bin/activate
    
  3. Once activated, your console should look like this:

    (.venv) <user>@<computer> <FolderName>
    

You can leave the virtual environment by executing deactivate.

Top comments (0)