Охватываемые темы: Installing packages, Upgrading and removing, requirements.txt, Virtual environment.
Installing packages
pip install requests # a specific package
pip install requests==2.31.0 # a specific version
pip install "requests>=2.28" # minimum version
pip install -r requirements.txt # from a file
Upgrading and removing
pip install --upgrade requests # upgrade
pip uninstall requests # remove
pip list # list installed packages
pip show requests # package details
requirements.txt
# Save the current environment
pip freeze > requirements.txt
# Install from a file
pip install -r requirements.txt
Contents of requirements.txt:
Django==5.0.1
djangorestframework==3.14.0
requests==2.31.0
Virtual environment
# Create
python -m venv venv
# Activate
source venv/bin/activate # macOS/Linux
venv\Scripts\activate # Windows
# Deactivate
deactivate
# Install packages into the environment
pip install django
pip vs Poetry vs uv
| Tool | Highlights |
|---|---|
pip |
Standard, simple |
poetry |
Lock file, dev/prod dependency separation |
uv |
Extremely fast (written in Rust) |
Searching for packages
pip search django # deprecated, use pypi.org instead
Security
pip audit # check for vulnerabilities
pip install pip-audit
Mirrors (if downloads are slow)
pip install django -i https://pypi.tuna.tsinghua.edu.cn/simple
💬 Comments (0)
No comments yet
Be the first to share your opinion about this article!