I have gotten some code from a colleague of mine written in Python for Windows. He is using several modules where files have the extension mymodule.pyw instead of mymodule.py. This works simply by doing
import mymodule
even if there is no file called mymodule.py. In Linux (Ubuntu 13.04 in my case) this does not work however. I get error messages of this form:
Traceback (most recent call last): File "main.pyw", line 27, in import core.main_window
ImportError: No module named main_window
simply renaming the module files to .py fixes the issue, but this is not desirable since I would like to use the same software on Windows and Linux.
Why is there this difference in the handling in Python and Windows and what can be done to fix it?
References: I seem to have found the original patch that added pyw support to windows, but with no argument as to why it shouldn't also apply to Linux.
The pyw extension exists for the windows version of python, since windows draws a strong distinction between CLI and GUI applications. Separate extensions map to separate python interpreters, py to python.exe (CLI) and pyw to pythonw.exe (GUI).
This is only relevant for the purposes of double clicking on python files to launch the proper interpreter; thus the only file that should logically have the pyw extension is the 'entry point' script that needs to be double clickable; all other files, even on windows can and should have the py extension instead.
On linux, neither pyw nor py particularly help making scripts double clickable, it should instead bear a "shebang" on the first line, and have executable file permissions (chmod +x). On unix, executables conventionally have no extension at all, but if you prefer, can still end in .pyw, linux doesn't care one bit!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With