In some cases setup.py needs to import some extra modules, e.g.:
from setuptools import setup
import foo
setup(
# e.g. a keyword uses `foo`
version=foo.generate_version()
)
If foo is not installed, the execution of setup.py will fail because of ImportError.
I have tried to use setup_requires, e.g. setup_requires=['foo'], but it doesn’t help.
So how to specify this kind of dependencies?
Dependencies needed in setup.py cannot be specified in the very setup.py. You have to install them before running python setup.py:
pip install -r requirements.txt
python setup.py install
pyproject.toml allows to specify custom build tooling:
[build-system]
requires = [..., foo, ...]
build-backend = "setuptools.build_meta"
I have thought out a trick — call pip to install the dependencies in setup.py
import pip
pip.main(['install', 'foo', 'bar']) # call pip to install them
# Now I can import foo & bar
import foo, bar
from setuptools import setup
setup(
...
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With