I'm working on distributing a Python package. It depends on the library lupa
. I want to run a post-install script that depends on lupa
that initializes some data within the package after it's been installed. After looking at some answers around StackOverflow, my stripped setup.py
essentially looks like this:
# setup.py
from distutils.core import setup
from setuptools.command.install import install
class PostInstallCommand(install):
def run(self):
# Do normal setup
install.run(self)
# Now do my setup
from mymodule.script import init
init()
setup(
# ...
install_requires = [
# ...
"lupa >= 1.10",
# ...
],
cmdclass = {
'install': PostInstallCommand
}
)
However, when emulating a fresh install/setup with tox
on Python 3.10, I get this error:
File "C:\My\Computer\Temp\pip-req-build-pl0jria3\setup.py", line 26, in run
from mymodule.script import init
File "C:\My\Computer\Temp\pip-req-build-pl0jria3\mymodule\script.py", line 28, in <module>
import lupa
ModuleNotFoundError: No module named 'lupa'
I was under the impression that anything put into install_requires
would be installed by the time setup()
finished, but that appears not to be the case (also corroborated by this answer). Is there anything I can do to ensure that lupa
is installed prior to mymodule.script.init()
, or is that stage of the setup process entirely out of the user's hands?