So today I did found out that with the release of pip 10.x.x
the req
package changed its directory and can now be found under pip._internal.r
I don't agree with the accepted answer. The setup.py
file can get ugly real fast if you have a large project with a lot of dependencies. It is always good practice to keep your requirements in a separate .txt
file. I would do something like this -
try: # for pip >= 10
from pip._internal.req import parse_requirements
from pip._internal.download import PipSession
except ImportError: # for pip <= 9.0.3
from pip.req import parse_requirements
from pip.download import PipSession
requirements = parse_requirements(os.path.join(os.path.dirname(__file__), 'requirements.txt'), session=PipSession())
if __name__ == '__main__':
setup(
...
install_requires=[str(requirement.requirement) for requirement in requirements],
...
)
Throw in all your requirements in requirements.txt
under project root directory.