Package Manager (pip)
Overview
• Python 2.7.6 and Python 3.4 or later includes by default
• Integrates with PyPI for packages
• Install, upgrade and uninstall package
• “requirements.txt” in projects provide input to pip
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Installation
# Install pip for python 2
sudo apt install python-pip
# Install pip for python 3
sudo apt install python3-pip
• After you pip installed a library or a executable script, it will store in the /bin directory
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
How to manage Python packages and libraries with pip, the Python package manager
pip list # list of packages installed
pip search redis # search for package
# Install a package
pip install <package>
# Ungrade a pakcage
pip install --upgrade <package>
# Uninstall a package
pip uninstall <package>
# View all packages installed
pip freeze
# Install packages in "requirements.txt"
pip install -r requirements.txt
python
import requests # import library
res = requests.get("http://tutorialinux.com")
res.status_code
req.__dict__
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Deploy a Python application's libraries and packages
with requirements.txt
• requirements.txt contains all the pacakges that you want to run pip to install on
'Freeze' installed Python packages into a requirements file
pip freeze > requirements.txt
tree myprogram
cat requirements.txt
# Output
# requests
# bs4
# redis
# Flask==0.11.1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Install a list of requirements from requirements.txt
pip install -r requirements.txt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Basic tips for using Python virtualenvs with Git
(.gitignore)
git init
vim .gitignore
# add venv to the .gitignore file
git status
Index