question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

API to parse requirements.txt for setup.py

See original GitHub issue

requirements.txt could a convenient single declarative point for specifying dependencies if it could be pasted into setup.py install_requires as-is. But requirements.txt contains comments and references to other requirements files, which seem to be incompatible with install_requires (reference needed).

It would be nice to have official API that parses requirements.txt file into a list suitable for install_requires section.

https://stackoverflow.com/questions/14399534/reference-requirements-txt-for-the-install-requires-kwarg-in-setuptools-setup-py

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:29
  • Comments:21 (14 by maintainers)

github_iconTop GitHub Comments

12reactions
mattvonrocketsteincommented, Nov 12, 2018

requirements.txt supports this, setup.py does not: git+https://github.com/user/repo.git@master#egg=loggable.

setup.py gives an error like this: error in setup command: 'install_requires' must be a string or list of strings containing valid project/version requirement specifiers; Invalid requirement, parse error at "'+https:/'"

stuff like this this is still a valid question and a confusing issue years and years later.

this api should exist and maybe parse requirements.txt to return a dictionary of {"dependency_links": [...], "install_requires": [....]} which is suitable to use like this: setup(<other_setup_keywords>, **parse_requirements('requirements.txt'))

12reactions
benoit-pierrecommented, Jul 9, 2017

There’s also no support for environment markers in install_requires requirements (e.g. python-xlib==0.19; "linux" in sys_platform will not work), something that is handled by extras_require.

Note that install_requires can just be a multi-lines string, so if you stick to a subset of pip’s requirements format that is supported by setuptools, you should be able to use something as simple as:

with open('requirements.txt') as fp:
    install_requires = fp.read()

setup(install_requires=install_requires, ...)

in your setup.py.

Also looks like a duplicate of #1074.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reference requirements.txt for the install_requires kwarg in ...
It is possible to parse a relatively simple requirements.txt file from a setuptools setup.py script without pip. The setuptools project already contains ...
Read more >
requirements-parser - PyPI
This is a small Python module for parsing Pip requirement files. The goal is to parse everything in the Pip requirement file format...
Read more >
requirements.txt vs setup.py in Python - Towards Data Science
The requirements.txt is a file listing all the dependencies for a specific Python project. It may also contain dependencies of dependencies, as discussed ......
Read more >
Welcome to Requirements Parser's documentation ...
Requirements parser is a Python module for parsing Pip requirement files. Requirements parser is (now) Apache 2.0 licensed. Quickstart: import requirements ...
Read more >
[Distutils] Parsing requirements, pip has no API ...
You're better off putting it > directly in setup.py and using setup.py to install dependencies in a > virtualenv instead of requirements.txt ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found