Skip to content

pip

prerequisites

make sure you've...

  • installed python

    sudo apt install -y python3-pip
    
    sudo pacman -S --noconfirm python-pip libffi
    

make sure you've...

  • installed python

    winget install -eh --Python.Launcher
    winget install -eh --Python.Python.$VERSION # (1)!
    
    1. $VERSION is the most recent python release (e.g. 3.12)

updating the global pip manifest

python -m pip install setuptools
python -m pip install --upgrade pip setuptools

if you run into issues here...

  • try forcing a reinstallation of both python pkgs

    python -m pip install --upgrade --force-reinstall pip setuptools 
    
  • try using a specific set of trusted hosts

    python -m pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --upgrade pip setuptools 
    
    • create a pip configuration file

      touch ~/.config/pip/pip.conf
      
    • with the following contents

      pip.conf
      1
      2
      3
      4
      5
      6
      [global]
      trusted-host = pypi.python.org
                  pypi.org
                  files.pythonhosted.org
                  raw.githubusercontent.com
                  github.com
      
    • create a pip configuration file

      touch ~/AppData/Roaming/pip/pip.ini
      
    • with the following contents

      pip.ini
      1
      2
      3
      4
      5
      6
      [global]
      trusted-host = pypi.python.org
                  pypi.org
                  files.pythonhosted.org
                  raw.githubusercontent.com
                  github.com
      

updating a pip manifest

python -m pip install --upgrade pip setuptools

exporting a pip manifest

make sure you've...

python -m pip freeze > requirements.txt

installing a pip manifest

make sure you've...

python -m pip install -r requirements.txt

note that...

  • it's good practice to use both a requirements.txt and a requirements-dev.txt
  • requirements.txt would contain all packages (with their versions' locked) required for the application
    requirements.txt
    ...
    mkdocs==1.5.3
    mkdocs-material==9.5.4
    mkdocs-material-extensions==1.3.1
    ...
    
  • requirements-dev.txt would contain all packages required for the development of the application
    requirements-dev.txt
    1
    2
    3
    4
    -r requirements.txt
    black
    pytest
    ...
    

uninstalling a pip manifest

make sure you've...

1
2
3
python -m pip freeze > uninstall.txt
python -m pip uninstall -y -r uninstall.txt
rm uninstall.txt

resources