How to use setup.py to install dependencies only?
Asked Answered
M

3

27

I am not interested in installing my package itself but I am interested installing all the dependencies used by my package. Is there a way to do this using setup.py? It seems setup.py installs my package and all dependencies.

Maximalist answered 12/6, 2015 at 7:1 Comment(4)
So, you have package abc which is dependent on xyz, you want to install xyz but not abc am i right ?Asset
pythonhosted.org/setuptools/…Edgebone
If the package you downloaded has a requirements file, it's as easy as pip install -r requirements.txt.Plumate
Please vote for this request to get a better solution: github.com/pypa/pip/issues/11440Bernhard
A
17

Use the -e flag on pip install

pip install -e .
Alienage answered 16/7, 2017 at 13:53 Comment(4)
I'm confused by this - -e is for "editable mode", which will do things like symlink the working directories of dependencies. In this case OP wants to install everything "for real", just not the one package under development. Does this handle the use case well?Repeat
@KenWilliams editable mode will install everything "for real", except for the very package you're working on (this will be "symlinked", as you mentioned). You might not want this link to remain though -- which is what your trick with as subsequent pip uninstall handles.Trinl
this is obviously not the right answer! Why is this accepted? This will do much more than "only install dependencies".Nemhauser
Please vote for this request to get a better solution: github.com/pypa/pip/issues/11440Bernhard
R
14

The only way I've found to reliably do this in a straightforward manner is this:

pip install . && pip uninstall `python setup.py --name`
Repeat answered 4/9, 2020 at 14:29 Comment(6)
Thanks, great answer. One minor suggestion: pip uninstall --yes, so it doesn't prompt you (e.g. in a Dockerfile)Trinl
This is great answer! One minor comment is that it does not work for python3, however it is easy to adapt.Latini
@QiLuo I use this with python 3, what problem did you encounter?Repeat
In an environment with both python2 and python3, I could use pip3 install . && pip3 uninstall `python3 setup.py --name` Latini
@QiLuo Yeah, that's just because pip and python are apparently called pip3 and python3 in your environment. In mine, they're simply called pip and python.Repeat
Please vote for this request to get a better solution: github.com/pypa/pip/issues/11440Bernhard
N
1

if you wan to do it from setup.py do:

python setup.py egg_info
pip install -r *.egg-info/requires.txt
rm -rf *.egg-info/

all of this ran from the project folder usually for me it's the root of my github where setup.py is.

credits: https://mcmap.net/q/297953/-pip-installing-only-the-dependencies

Nemhauser answered 12/6, 2015 at 7:2 Comment(1)
Exactly what I wanted for my docker container!Christachristabel

© 2022 - 2024 — McMap. All rights reserved.