1. Virtual Environments

This is the first, critical piece to modern software development with Python.

A Virtual Environment is required

PyCharm creates a venv by default when you create a new Project.

You can skip this step if you already have a Virtual Environment in your Project

What is a Virtual Environment?

Without Virtual Environments (venv or .venv), everything you install would be global to your machine. Every project you have would be sharing the same packages and dependencies which could cause clashes or unwanted side effects.

Luckily, venvs are easy to setup. Open a Terminal in the context of your Project Directory.

We assume you already have python3 installed on your machine

$ python3 --version
# should print 3.x.x

$ python3 -m venv "venv"

Download Python if you haven't already https://www.python.org/downloads/

Depending on your IDE, it should automatically detect that a Virtual Environment has been created and ask if it should use it. Accept :)

Otherwise, you can manually configure your IDE to use the Virtual Environment.

1. Install the Python extension
2. Open the Command Palette (CMD + SHIFT + P or CTRL + SHIFT + P)
3. Search for "Python: Select Interpreter"
4. Select the venv for your Project

Kill all Terminal sessions, then reopen a Terminal. It should now open and activate the Virtual Environment automatically. This is indicated by the (venv) prefix as seen in the example below:

New Terminal
$ (venv) python --version
# should print 3.x.x for Mac or Windows.
# Mac users don't need to use python3 or pip3 anymore!

Real Python goes more in-depth on their website: Virtual Environments

Last updated