Tom Purl
Tom Purl

Reputation: 529

Install Package Using setup.py and Excluding Dependencies

I am interested in running a script that is part of a rather large Python package. The package structure looks something like this:

MyApp
|
--setup.py
|
--MyApp
  |
  --foo
  |
  --scripts/some-tiny-script.py

some-tiny-script.py only relies upon a few simple 3rd-party libs and the MyApp package itself.

I would like to only install the dependencies that some-tiny-script requires without installing everything listed in the install_requires section of the setup.py file. This is because it contains many libraries, some of which are very large. I'm ok with identifying the libraries needed by some-tiny-script.py and installing those with pip, but how do I install MyApp without installing everything listed under install_requires?

Upvotes: 2

Views: 469

Answers (1)

Tom Purl
Tom Purl

Reputation: 529

Thank you Mikko! I was confused by the overlap between what the pip install and setup.py install commands do. Here's what I ended up doing:

  1. cd MyApp (The one containing setup.py)
  2. pip install -e --no-deps This install MyApp. It also posts a lot of warnings but that's ok.
  3. Run my script and get errors about missing dependencies
  4. Install dependencies individually using pip. GOTO 3.
  5. Once my script no longer throws errors I'm done :-)

This is an unwieldy process for large scripts or apps but for small scripts it's doable and saves me multiple gigabytes of storage space in my Docker image.

Upvotes: 1

Related Questions