Create a Python Development Environment

Examples

How to create a python development environment

Check if Python is installed

python3 --version

Install using Homebrew

brew install python

Verify Installation

which python3
python3 --version

Create Project Folder

mkdir myproject
cd myproject

Initialise Git Repo

git init

Create the Virtual Environment

python3 -m venv .venv

this creates

myproject/
 ├── .venv/
 └── (your project files)

Activate the Virtual Environment

source .venv/bin/activate

your terminal should look like this

(.venv) john@MacBookPro myproject %

To Deactivate later

deactivate

Install Dependencies

pip install requests
pip install fastapi

Create a requirements.txt

pip freeze > requirements.txt

to install using the requirements.txt

pip install -r requirements.txt

Add .venv to .gitignore

vi .gitignore

.venv/
__pycache__/
*.pyc
.env

Open VS-Code

code .

Setup VS-Code

  1. Open project folder.

  2. Press Cmd + Shift + P

  3. Type: Python: Select Interpreter

  4. Choose:

./.venv/bin/python