1

I have a python program that, using setuptools, I can build producing an egg or wheel file.

I'm trying to understand the correct way to make this program easily distributable. I would like to be able to give a single file to another linux machine (probably Ubuntu) and run a few commands, and then execute the program directly.

Currently I can install the program, which allows it to be run as follows:

$ python3 -m myprogram

This would be fine if my goal was to be able to import it into other Python programs, but I'd rather have it runnable from anywhere ... like grep or other utilities.

I understand that it is more typical to add a shebang to a script, but I'm trying to make something that can be easily shared, even when there are multiple files and dependencies, and even when the recipient doesn't have typical Python tools like pip available.

Eric Wilson
  • 57,719
  • 77
  • 200
  • 270
  • 2
    You can [include `console_scripts` in your package's `entry_points`](http://www.scotttorborg.com/python-packaging/command-line-scripts.html) (declared in `setup.py`). This will still require `setuptools` to be present and the package to be installed, but will allow you to call the package without needing `python3 -m ...`. – Thomas Orozco Sep 15 '15 at 10:30
  • You may want to try [Python Zip Application Archive Format](https://docs.python.org/3/library/zipapp.html#the-python-zip-application-archive-format). – Audrius Kažukauskas Sep 15 '15 at 10:46
  • @ThomasOrozco Thanks much, that did it. – Eric Wilson Sep 15 '15 at 10:49
  • See [Set PYTHONPATH according to requirements.txt at runtime](http://stackoverflow.com/q/38642658/95735) and don't be mislead by the title which is unfortunate. – Piotr Dobrogost Sep 09 '16 at 15:08
  • 1
    Sadly, the tutorial referenced by @ThomasOrozco gives a 404 now. Using the wayback machine, it is available at https://web.archive.org/web/20160402114428/http://python-packaging.readthedocs.org/en/latest/command-line-scripts.html – hlongmore Jul 23 '20 at 03:43
  • @hlongmore If someone were to extract a useful answer from that tutorial, I'd upvote and accept. Would probably be more robust for the one that finds his way here in 2025. – Eric Wilson Jul 23 '20 at 15:18

0 Answers0