Installing packages using pip and virtual environments

This guide discusses how to install packages using pip and a virtual environment manager: either venv for Python 3 or virtualenv for Python 2. These are the lowest-level tools for managing Python packages and are recommended if higher-level tools do not suit your needs.

Note

This doc uses the term package to refer to a Distribution Package which is different from an Import Package that which is used to import modules in your Python source code.

python3 -m pip install --user --upgrade pip

python3 -m pip --version
pip 21.1.3 from $HOME/.local/lib/python3.9/site-packages (python 3.9)
py -m pip install --upgrade pip

py -m pip --version
pip 21.1.3 from c:\python39\lib\site-packages (Python 3.9.4)
python3 -m pip install --user virtualenv
py -m pip install --user virtualenv
python3 -m venv env
py -m venv env
source env/bin/activate
.\env\Scripts\activate
which python
where python
.../env/bin/python
...\env\Scripts\python.exe
deactivate
python3 -m pip install requests
py -m pip install requests
Collecting requests
  Using cached requests-2.18.4-py2.py3-none-any.whl
Collecting chardet<3.1.0,>=3.0.2 (from requests)
  Using cached chardet-3.0.4-py2.py3-none-any.whl
Collecting urllib3<1.23,>=1.21.1 (from requests)
  Using cached urllib3-1.22-py2.py3-none-any.whl
Collecting certifi>=2017.4.17 (from requests)
  Using cached certifi-2017.7.27.1-py2.py3-none-any.whl
Collecting idna<2.7,>=2.5 (from requests)
  Using cached idna-2.6-py2.py3-none-any.whl
Installing collected packages: chardet, urllib3, certifi, idna, requests
Successfully installed certifi-2017.7.27.1 chardet-3.0.4 idna-2.6 requests-2.18.4 urllib3-1.22
python3 -m pip install 'requests==2.18.4'
py -m pip install "requests==2.18.4"
python3 -m pip install 'requests>=2.0.0,<3.0.0'
py -m pip install "requests>=2.0.0,<3.0.0"
python3 -m pip install --pre requests
py -m pip install --pre requests
python3 -m pip install 'requests[security]'
py -m pip install "requests[security]"
cd google-auth
python3 -m pip install .
cd google-auth
py -m pip install .
python3 -m pip install --editable .
py -m pip install --editable .
google-auth @ git+https://github.com/GoogleCloudPlatform/google-auth-library-python.git
python3 -m pip install requests-2.18.4.tar.gz
py -m pip install requests-2.18.4.tar.gz
python3 -m pip install --no-index --find-links=/local/dir/ requests
py -m pip install --no-index --find-links=/local/dir/ requests
python3 -m pip install --index-url http://index.example.com/simple/ SomeProject
py -m pip install --index-url http://index.example.com/simple/ SomeProject
python3 -m pip install --extra-index-url http://index.example.com/simple/ SomeProject
py -m pip install --extra-index-url http://index.example.com/simple/ SomeProject
python3 -m pip install --upgrade requests
py -m pip install --upgrade requests
requests==2.18.4
google-auth==1.1.0
python3 -m pip install -r requirements.txt
py -m pip install -r requirements.txt
python3 -m pip freeze
py -m pip freeze
cachetools==2.0.1
certifi==2017.7.27.1
chardet==3.0.4
google-auth==1.1.1
idna==2.6
pyasn1==0.3.6
pyasn1-modules==0.1.4
requests==2.18.4
rsa==3.4.2
six==1.11.0
urllib3==1.22