-
Install Python 3
- On a Unix-based OS, the system's default Python installation is normally Python 2. Check this by running
python --version
on a terminal. If this is so, install Python 3 but DO NOT REMOVE / OVERWRITE / UNINSTALL the old Python 2. The system uses Python 2 for its internal scripts and removing it may break the OS installation. - For Linux, either install it from
apt
or from source - For Mac, use Homebrew
- Verify the Python installation by running
$ which python3 $ python3 --version
- On a Unix-based OS, the system's default Python installation is normally Python 2. Check this by running
-
Setup and use a virtual environment
- There are many different modules for creating a virtual environment
- If Python 2 support is needed, use the virtualenv module
- If Python 3 only, use the built-in venv or poetry
- For
venv
- Set
VENV_DIR
to directory for virtual environments (ex.$HOME/.venvs
) - Copy the bash aliases for using venv
mkvenv PROJECT_NAME
upvenv PROJECT_NAME
dnvenv
rmvenv PROJECT_NAME
lsvenv
- Set
- For
poetry
- For
-
For each Python project
- For
virtualenv
andvenv
- Create/Activate a virtual environment
$ mkvenv NAME /path/to/python
- Create a requirements.txt file
$ pip freeze > requirements.txt
- Commit the requirements.txt file
- When switching environments:
$ pip install -r requirements.txt
- Create/Activate a virtual environment
- For
poetry
- Specify the Python version to use
$ cd <project> $ poetry env use python3 $ poetry env use python3.X # 3.7, 3.8, 3.9, 3.10, 3.11
- Initialize the project
$ poetry init
- Install packages
$ poetry add <package> $ pipenv add --dev PACKAGE
- Commit the generated
pyproject.toml
andpoetry.lock
- Activate the environment
$ poetry shell
- Specify the Python version to use
- For
- The FAQ list every Python developer MUST first read
- How does
import
work? - Public and Private
- Metaclasses
- black - no-config, opinioniated formatter
- ipython - Enhanced interactive Python shell
- colorama - Cross-platform colorizer for console logs
- click - For creating CLI-based applications
- typer - For creating CLI-based applications with type-hinting support
- tqdm - For better progress bars and loop tracking
- flask - Lightweight web application framework
- fastapi - Modern framework with async support, type-hints, and auto-generated documentation
- pydantic - Data validation through type hints
- bokeh - Interactive and embeddable images for modern web browsers