- [[python - venv]], [[python - uv]]
# Idea
The `requirements.txt` is a configuration file that tells `pip` (package manager for Python) what to install in your Python environment. This file name is arbitrary but `requirements.txt` is often used. Put `requirements.txt` in the directory where the command will be executed. If it is in another directory, specify the path.
```sh
# install packages listed in requirements.txt
pip install -r requirements.txt
# prints package and environment information
pip freeze
# save output of pip freeze
pip freeze > requirements.txt
# upgrade package x
pip install --upgrade x
# upgrade pip
pip install --upgrade pip
# get info about a pacakge x
pip show x
# uninstall package x
pip uninstall x
# show all installed packages
pip list
# show outdated packages
pip list -o
```
Or you can write your own configuration file (`requirements.txt`)
```txt
# comments can be added too
###### Requirements without Version Specifiers ######`
nose
nose-cov
beautifulsoup4
###### Requirements with Version Specifiers ######`
docopt == 0.6.1 # Version Matching. Must be version 0.6.1
keyring >= 4.1.1 # Minimum version 4.1.1
coverage != 3.5 # Version Exclusion. Anything except version 3.5
Mopidy-Dirble ~= 1.1 # Compatible release. Same as >= 1.1, == 1.*
# Use commma for AND
# version 1.0 or greater AND 2.0 or less
package >= 1.0, <=2.0
```
**If the version is omitted, the latest version is installed**. Two conditions can be specified with AND by separating them with a comma.
# References
- https://note.nkmk.me/en/python-pip-install-requirements/
- https://flaviocopes.com/python-pip/