0

I have a Python3 CLI (using Click) with the following setup.py:

from setuptools import setup, find_packages

setup(
    # ...
    entry_points='''
        [console_scripts]
        importdb=scripts.importdb:cli
    ''',
)

This works if I do pip install -e .: I can just run importdb ... from the command line. How can I package this into an executable file that can be run without pip install -e?

I have tried python setup.py bdist_egg, which produces an egg file, but trying to execute it gives Syntax error: word unexpected (expecting ")"). I'm not really sure where to go from here - I've searched for instructions on this but nothing seems to work.

Bluefire
  • 13,519
  • 24
  • 74
  • 118
  • https://stackoverflow.com/search?q=%5Bpython%5D+standalone+executable – phd Apr 01 '20 at 12:07
  • @phd Thanks! I did see that question, but it doesn't quite answer mine. That question talks about running a given .py file as a standalone executable. I have a python package with entry points declared in setup.py, and I want those entry points to be exposed via the executable. – Bluefire Apr 01 '20 at 23:52

1 Answers1

1

Use pip install. Then copy to resulting /path/to/venv/bin/importdb script to wherever you want (maybe somewhere on your PATH, like .local/bin/importdb). As long as the venv stays at the same location on the file system, it should work fine, since the importdb script has the full path /path/to/venv/bin/python as its shebang. Otherwise look into things like pex, shiv, zipapp.

sinoroc
  • 18,409
  • 2
  • 39
  • 70