Search code examples
pythonpiprequirements.txt

How to install packages with pip and a requirements.txt file ignoring some packages


I'm doing a script to automatize the downloading and the installation of a repository from GitHub. However, my environment needs some special dependencies which aren't specified in requirements.txt file. So, my goal is:

  1. Download the repository with git clone
  2. Install dependencies with pip install -r requirements.txt but ignoring the bad dependencies
  3. Install ignored dependencies with my correct version of them (I use wget file.whl and pip install file.whl)

My question is, how can I ignore the packages from the requirements.txt file with the pip install command? I know that I can open file, comment or erase that lines and install with pip, but I want to achieve with a full automatization task.


Solution

  • Solution 1: If the file.whl have the same version as your ignored packages, you can just flip 2 and 3 and it should be ok.

    Solution 2: if the file.whl have a different version than your ignored packages, you can remove them dynamically from the pip file. For example (Linux), using:

    pip install -r $(grep -v '^ *#\|^pkg1\|^pkg2' requirements.txt | grep .)

    Similar procedure can be done in powershell in windows.

    Note: solution 2 code was taken directly from https://www.shellhacks.com/pip-install-requirements-exclude-specific-packages/