1

I'm trying to make my Python command-line app as self-installing as possible for some Mac users in my company by registering it as a "command-line accessible tool" using setup.py as described here.

My project tree (simplified) looks like so:

my-app
 |-app.py
 |-setup.py

Building off Kenneth Reitz's example, here's my setup.py script:

setup(
    name=my-app,
    ...
    packages=find_packages(exclude=('tests',)),

    # For entry point. Based on https://stackoverflow.com/a/28471597/9381758.
    py_modules=['app'],

    # Based on https://stackoverflow.com/a/11717581/9381758.
    entry_points={
        'console_scripts': ['my-app = app:main']
    }
)

When I run python setup.py install, it installs to my pyenv directory:

~/.pyenv/versions/3.6.4/bin/my-app

This works:

$ ~/.pyenv/versions/3.6.4/bin/my-app -h 
usage: my-app [-h]

This doesn't:

$ my-app -h 
-bash: my-app: command not found

Is there an elegant way to update my setup.py script so that after install end-users will be able to run the my-app command without further tweaks or including the full path?

Tom at FFI
  • 177
  • 12

1 Answers1

0

This could solve your problem.

setup(
    other args ...
    scripts = ['my-app/script.py']
)

In your case try

setup(
    other args ...
    scripts = ['app.py']
)
klim
  • 1,179
  • 8
  • 11
  • I considered this, but then wouldn't I have to call `app -h`? I like the idea of aliasing the command. Using the first example I could achieve that effect by writing a wrapper script under `bin/my-app` but that feels fussy and redundant. Alternately, if I followed Python convention and renamed `app.py` to `my_app.py`, I guess that would also sorta work. – Tom at FFI Mar 09 '18 at 06:15