2

I develop a python package that, at the moment, consists of sub-packages, modules and functions that can be found in these modules. Now, I have a script, that uses certain elements of the package (as well as other packages), and I want to ship this script with the package. The goal in mind is that a potential user could, after installing the package, simple run the script and get the results.

What is the right way to do it? I could simply include the script in the tree structure of the package, and then it will be included with the distribution. But, in turn, the package will be installed on the user's box in a directory that is normally not too accessible to the user.

Dror
  • 12,174
  • 21
  • 90
  • 160

2 Answers2

2

If your package is being distributed with setuptools or something similar, you can use the scripts keyword and setuptools will place it correctly in the PATH. See Command Line Scripts

  • Plus, for this to work under windows, it seems like the box has to be restarted... errrr... – Dror Oct 30 '14 at 14:07
0

Distutils supports installing scripts, but the question of where to place them for user access is a more complex one (for instance, Windows uses file extensions rather than shebangs and AFAIK doesn't have a facility to register them as commands). Scripts that are installed along with a module traditionally test using __name__=='__main__' if they are the primary program, and can be run from there using (for example) python -m SimpleHTTPServer.

Yann Vernier
  • 15,414
  • 2
  • 28
  • 26