2

I am distributing a simple library/application which includes a script with GUI. Under windows I want this to be run by pythonw.exe, preferrably by making it a .pyw file.

root/
    lib/
        lib.py

    guiscript.py
    setup.py

I want the user to be able to install guiscript in any path.

I stole this hook from this question:

from distutils.core import setup
from distutils.command.install import install
import os, sys

class my_install(install):
    def run(self):
        install.run(self)
        try:
            if (sys.platform == "win32") and sys.argv[1] != "-remove":
                os.rename("guiscript.py",
                          "guiscript.pyw")
        except IndexError:pass

setup(...
      cmdclass={"install": my_install})

But this doesn't work because it changes the name of guiscript.py in the source folder, because the path is relative to setup.py.

Is there a reasonable way to get the script install-path, or alternativly a simple way to find guiscript.py (it's not given it's in PYTHONPATH).


So because I don't have 50 karma i can't answer my own post in 7 hours but here it is:

Okay, I found the solution. I can delete the question if you want, but for now I'll keep it in case someone else has the same question.

from distutils.core import setup
from distutils.command.install_scripts import install_scripts
import os, sys

class my_install(install_scripts):
    """Change main script to .pyw after installation.

    If sys.argv == '-remove'; it's ran as uninstall-script.
    Override run() and then call parent."""
    def run(self):
        install_scripts.run(self)
        try:
            if (sys.platform == "win32") and sys.argv[1] != "-remove":
                for script in self.get_outputs():
                    if script.endswith("guiscript.py"):
                        os.rename(script, script+"w")
        except IndexError:pass

setup(...
      cmdclass={"install_scripts": my_install}
     )
Community
  • 1
  • 1
jacwah
  • 2,727
  • 2
  • 21
  • 42
  • Here are 3 links that contain some useful info re: your problem.http://stackoverflow.com/questions/1689015/run-python-script-without-dos-shell-appearing http://stackoverflow.com/questions/1813872/running-a-process-in-pythonw-with-popen-without-a-console http://stackoverflow.com/questions/3390762/how-do-i-eliminate-windows-consoles-from-spawned-processes-in-python-2-7 – Jason White Feb 14 '13 at 21:35

0 Answers0