Collection of Python code examples for my blog F7L8C9.
Licensed under the MIT License. See file LICENSE.
Some examples need external libraries. Install these with pip.
pip install <package>
to install packagepip install --upgrade <package>
to upgrade installed packagepip list
- to list packages in the current environmentpip list --outdated
- to list outdated packagespip show <package>
- to get details about a package that is installed in the current environmentpip uninstall <package>
to uninstall packageCreate repeatable installations with the following commands.
pip freeze > requirements.txt
pip install -r requirements.txt
File requirements.txt
should be checked into source control. See also Installing Python Modules.
Create virtual environments with the venv module.
python -m venv .venv
On Linux bash, activate environment with source .venv/bin/activate
.
Or, alternatively with virtualenv.
virtualenv venv
Directory .venv/
should be ignored by source control.
See Pipenv for a more sophisticated virtualenv management tool.
See pyenv to set up and use several Python versions in parallel.