2

I am working on a standalone Python-GUI-program. When I run

python3 setup.py sdist

I get the following warning:

package init file 'main-application-folder/__init__.py' not found (or not a regular file)

Is this warning only meant for packages or should a standalone Python program also have an __init__.py instead of something like main-window.py or my-first-program.py?

Should I rename my main file (in my case ìbk-st.py to __init__.py) or would it be good to retain a certain structure in the __init__.py (i.e. make a separate file that calls the ibk-st.py file)

Link to project:

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
tobias47n9e
  • 2,233
  • 3
  • 28
  • 54
  • 1
    It's not clear what distinction you're drawing between *"packages"* and a *"standalone Python program"* - packages generally *are* standalone programs. You have numerous `.py` files grouped together in a directory, so yes you should write an `__init__.py` to specify what should be exposed publicly from them. – jonrsharpe Feb 19 '15 at 17:56
  • This answer might help you: http://stackoverflow.com/questions/28444747/whats-the-minimal-directory-structure-to-make-setuptools-work-with-one-file-py/28573255#28573255 – Iguananaut Feb 19 '15 at 18:17
  • @jonrsharpe: Sorry to be so easily confused but does that mean I should rename my ibk-st.py to `__init__.py` or are there certain specifications that an `__init__.py` should fulfil? – tobias47n9e Feb 19 '15 at 18:21
  • @Spießbürger I suppose you *could*, but that would be unconventional - `__init__.py` usually contains very little code, just imports of the names you want to expose externally. See e.g. http://stackoverflow.com/q/448271/3001761 – jonrsharpe Feb 19 '15 at 18:22
  • you have packages = ["ibk-st"] in your setup.py, so naturally distutils ask for a __init__.py in the package. If you don't want to distribute a package just use only py-modules. – mkiever Feb 19 '15 at 18:24
  • @jonrsharpe: That clears up my confusion a lot. I would accept it, if you post it as an answer. – tobias47n9e Feb 19 '15 at 18:25
  • @mkiever: Is that a mistake? I just started experimenting with packaging a few days ago. So I am still not sure what best practices are. – tobias47n9e Feb 19 '15 at 18:26
  • @mkiever: Thank you i will read up on the `packages = ` option! – tobias47n9e Feb 19 '15 at 18:34
  • @Spießbürger: Take a look at the Simple Example in the Introduction of distutils documentation for an example without packages – mkiever Feb 19 '15 at 18:50

1 Answers1

2

You should rename the ibk-st into a valid package identifier for python (ibk_st maybe); then ibk-st.py into something like main_ui.py; then have an __init__.py for that whole package (alternatively you can rename ibk-st.py to __init__.py).

Do note that setup.py can install command line scripts; you can provide a thin wrapper as file bin/ibk-st-ui with contents

#!/usr/bin/env python

from ibk_st.main_ui import main
main()

The module installation will ensure that the script is runnable on whatever platform the user is using.

Then in your setup.py you should have

...
packages = [ 'ibk_st' ],
scripts=[ 'bin/ibk-st-ui' ],
...

Now when you run the setup.py install or install the package, the modules can be embedded into other programs and the command ibk-st-ui will be installed in the the bin folder (be it the bin of a virtualenv or the system /usr/local/bin), that can run the UI.