While installing from requirements.txt, as under:
pip install -r requirements.txt
I want to restrict to a context of Python3 only. If attempted from Python2 context, it should throw an error.
How can I accomplish the above?
While installing from requirements.txt, as under:
pip install -r requirements.txt
I want to restrict to a context of Python3 only. If attempted from Python2 context, it should throw an error.
How can I accomplish the above?
Turn your project into a proper package, and make use of the python_requires
string. If you want to be absolutely sure (i.e. ensure older versions of pip
will also not run under Python 2), in the setup.py
include something like this before the setup
call
from setuptools import setup
import sys
if sys.version_info < (3,):
raise RuntimeError('unsupported python version')
setup(...
Naturally, declare all the dependencies in the setup.py
so that other packages that depend on this one will get them without having to rely on a separate file.
If you still want to make use of requirements.txt
, also add this to the following:
-e .
Which will trigger your package to be installed, thus setup.py
should be invoked and then the exception will be raised which should abort the installation.