Python Install & Virtual Environment
Last updated
Download Python 3.12 from python.org/downloads. Choose the installer for your operating system (Windows, macOS, or Linux).
Run the installer. On Windows, check Add python.exe to PATH before clicking Install.
Verify the installation by opening a terminal and running:
python3 --versionYou should see Python 3.12.x. On Windows, use python --version instead.
If Windows opens the Microsoft Store when you type python, the PATH was not set during installation. Re-run the installer, select Modify, and ensure the PATH checkbox is enabled.
Create a new directory for your work:
mkdir helloworld && cd helloworldCreate a file named app.py with the following content:
print("Hello, World!")Run it:
python3 app.pyOn Windows use python app.py. You should see Hello, World! printed to the terminal.
A virtual environment isolates the Python packages for one project from those of another. Without it, installing a package for one project can break a different project that depends on a different version of the same package.
You will create a virtual environment in every project directory throughout this course.
Use the built-in venv module to create an environment named venv at the root of your project:
Activate it before installing any packages:
macOS / Linux:
Windows:
When activated, your terminal prompt shows the environment name (e.g., (venv)). All pip install commands now install into this isolated environment.
With the environment active, install packages normally:
Packages are stored inside the venv/ directory and do not affect your system Python or other projects.
When you are finished working:
This returns you to the system Python. The installed packages remain inside venv/ for next time.
Name the environment venv/ and add it to .gitignore so it is never committed to version control.
Re-create the environment on a new machine by running python3 -m venv venv and then pip install -r requirements.txt (once you start tracking dependencies in a requirements file).
Always activate the environment before running project code or installing packages.
Last updated
python3 -m venv venvsource venv/bin/activatevenv\Scripts\activatepip install requestsdeactivate