Create a Python Development Environment
Examples
How to create a python development environment
Check if Python is installed
python3 --versionInstall using Homebrew
brew install pythonVerify Installation
which python3
python3 --versionCreate Project Folder
mkdir myproject
cd myprojectInitialise Git Repo
git initCreate the Virtual Environment
python3 -m venv .venvthis creates
myproject/
├── .venv/
└── (your project files)Activate the Virtual Environment
source .venv/bin/activateyour terminal should look like this
(.venv) john@MacBookPro myproject %To Deactivate later
deactivateInstall Dependencies
pip install requests
pip install fastapiCreate a requirements.txt
pip freeze > requirements.txtto install using the requirements.txt
pip install -r requirements.txtAdd .venv to .gitignore
vi .gitignore
.venv/
__pycache__/
*.pyc
.envOpen VS-Code
code .Setup VS-Code
-
Open project folder.
-
Press Cmd + Shift + P
-
Type: Python: Select Interpreter
-
Choose:
./.venv/bin/python