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)

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, cherished by the supportive DEV Community. Coders of every background are encouraged to bring their perspectives and bolster our collective wisdom.

A sincere “thank you” often brightens someone’s day—share yours in the comments below!

On DEV, the act of sharing knowledge eases our journey and forges stronger community ties. Found value in this? A quick thank-you to the author can make a world of difference.

Okay