0

Installing with pip, I can write the following requirements.txt file:

git+https://repo@branch#egg=foo&subdirectory=this/bar/foo
numpy

And successfully install the requirements file:

python3 -m pip install -r requirements.tx

However, I have co-located in the directory a setup.py script that lists:

setuptools.setup(
  ...
  install_requires = get_lines('requirements.txt'),
  ...
)

And installing this submodule using pip involves pip running setup.py...which fails to handle the module link:

git+https://github.com/repo@branch#egg=foo&subdirectory=this/bar/foo

I can see a lot of ways around this, but it seems like there should be one non-ambiguous way to do this which changes as little as possible in the setup.py script.

Is there such a way?

1 Answer 1

1

You probably need to change the line in requirements.txt to something like:

foo @ git+https://repo@branch#egg=foo&subdirectory=this/bar/foo

References:

Although I am not entirely sure it will work. There might be subtle differences between the notations accepted in requirements.txt files, pip directly and setuptools. In particular I do not know how well things like egg and subdirectory are supported.

Advices:

  • Avoid calling python setup.py install or python setup.py develop from now on, and make sure to call python -m pip install . or python -m pip install --editable . instead.
  • I do consider reading requirements.txt from within setup.py as a red flag (or at least yellow). The contents of install_requires of setuptools and requirements.txt usually serve different purposes.
Sign up to request clarification or add additional context in comments.

6 Comments

So I probably need to add information: I am installing with python3 -m pip install foo. And I do like the editable flag, but I am not using it here. Also, setup and requirements may be for different purposes at some point. But I have stripped down the requirements file so that it consists of exactly what is needed for a valid install. Also, if I could drop the setup pattern entirely, I would do it -- no vested, habitual or idiomatic interest in that on my end.
In other words, in this particular use case, the setup.py is more of a ritual than a feature. Pip needs to come in, install the requirements, and install all the python files in the directory.
@Chris So have you tried the foo @ ... notation or not? -- If I recommend calling pip instead of setup.py, it is because setuptools doesn't understand this foo @ notation, or at least it didn't last time I checked. Which is fine, setuptools does not really need to understand that notation, it just writes verbatim the line in the distribution metadata. -- For the install_requires vs. requirements.txt, fair enough, just a warning that it might be a symptom for some deeper misunderstanding, but you seem to know what you're doing on this front, so all good.
If you want to get rid of setup.py, I would recommend looking into replacing it with the combination setup.cfg + pyproject.toml.
all worked! and got setup.py figured out too.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.