I use python click package and setuptools to create a simple command line. And I work in a pipenv virtualenv.
My working directory is like this:
jkt/scripts/app.py
And my setup.py is like this:
from setuptools import setup, find_packages
setup(
name='jkt',
version='0.1',
packages=find_packages(),
include_package_data=True,
entry_points='''
[console_scripts]
jktool=jkt.scripts.app:my_function
''',
)
Then I run the command
pip install --editable .
And run jktool to execute my_function but I get the error:
ModuleNotFoundError No module named 'jkt'.
But when the app.py in jkt directory I can run my function
setup(
name='app',
version='0.1',
py_modules=['app'],
entry_points='''
[console_scripts]
app=app:jktools
''',
)
After I run pip install -e . I can use app command to run my function.
app.pywithdef somefunction(): print("Works"), and installing with--user(to avoid global install). I can get anImportErroron Python 2.7 (if I don't put empty__init__.pyfiles injkt/andjkt/scripts/), but for modern Python 3.7 (whereModuleNotFoundErroris anImportErrorsubclass and implicit namespace packages are a thing), it works just fine.