Python¶
Conventions¶
- PEP 8 styling guideline walkthrough
- Using the flake8 linter - checks for errors (including failing to comply with PEP 8 guidelines
- Meaning and naming conventions around single and double underscores
Imports¶
Pip¶
Package installer.
Command | Description |
---|---|
pip install <package> |
Install the latest version of a package |
pip install <package>==<version> |
Install the specified version of a package |
pip install -r requirements.txt |
Install the packages from a requirements.txt file |
pip list --outdated |
View outdated packages |
pip install --upgrade <package> |
Upgrade the desired packages |
pip uninstall <package> |
Uninstall a package |
If pip has not been added to the path, replace pip
with python -m pip
in the commands above.
Pyenv¶
Easily switch between multiple versions of Python.
Scripting¶
- Built-in library for command-line parsing: argparse tutorial
- Built-in library for logging: logging tutorial
- Testing framework: PyTest tutorial
- Built-in exceptions
- Regular expressions tutorial
- Top data science libraries
Virtual Environments¶
Bundle all the packages and their versions to run an application so that they do not conflict with the globally installed python packages.
-
Create virtual environment directory (suggested name:
.venv
). -
Activate virtual environment. Use the active shell's corresponding
activate
script. -
Install the required packages: pip section
-
Create/update the
requirements.txt
file (to record the versions of packages used in the project) -
Exit the virtual environment
VS Code integration
After selecting .venv/bin/python
to be the Python interpreter, terminals and debuggers will run
in the virtual environment by default.