What I am trying to achieve
My goal is, after installing the python package, to be able to run a command from a script that was not installed together.
Example
$ excommandHello!Directory Structure
.├── A├── __init__.py└── cli.py├── .venv├── pyproject.toml├── setup.cfg├── extra.py└── extra_test.pycli.py
import importlibdef main(): getattr(importlib.import_module('extra'), 'hello')()extra.py
def hello(): print("Hello!")extra_test.py
import importlibgetattr(importlib.import_module('extra'), 'hello')()pyproject.toml
[build-system]requires = [ "setuptools" ]build-backend = "setuptools.build_meta"setup.cfg
[metadata]name = Aversion = 1.0.0[options]packages = find:[options.entry_points]console_scripts = hello = A.cli:mainThe Problem
After installing the package:
$ pip install .The command hello does not work because importlib raises an Error:
$ helloModuleNotFoundError: No module named 'extra'What was tried
I have assured that has something to do with the installation or importlib, because if I run python3 extra_test.py it runs normally and it does exactly the same as the command hello is suposed to do.