Python application launcher (for Python code)

Steve D'Aprano steve+python at pearwood.info
Mon Feb 20 19:53:27 EST 2017


On Tue, 21 Feb 2017 04:04 am, Deborah Swanson wrote:

> That's a good idea, you can do just about anything from a shell, and I
> read that Linus Torvalds never uses anything except the shell.
[...]
> Since I will be in Windows for yet awhile, it would be ideal to find an
> application that will work in both Windows and Linux, and maybe a shell
> installed in Windows is the way to go.

Windows has a console application with a shell. It is pretty bare bones, but
it works. If I remember the steps correctly (and hopefully some Windows
user will step in and correct me if I get it wrong):

Start menu > Run > type "cmd" ENTER


I'm told that serious Windows power users don't use cmd.exe or command.com
(or is it the other way around?) any more, they use Powershell, but I know
nothing about that.

If you're using Windows 10, you might look at Windows Subsystem for Linux:

https://blogs.windows.com/buildingapps/2016/03/30/run-bash-on-ubuntu-on-windows/


> But even within the shell I'd 
> want something to act as a Python application launcher (see my previous
> post for details), although using just the shell itself to locate and
> launch Python code is an option.

Normally the way I would launch applications is:

- from the Start menu (yes, many Linux desktops have a Start menu);

- from the shell.


The Start menu is configurable under Linux, although I've never done so,
I've always let the OS manage it.

At the shell, there are plenty of ways to organise things. It depends on how
you want to launch your apps:


python path/to/my/application.py

python -m application.py

path/to/my/application.py

application.py


except on Windows you might have to use python.exe or py.exe instead of
python.

The first is the most flexible: you can organise your scripts and
applications however you like, wherever you like, and then just explicitly
run them.

The last is the trickiest: on Linux, the file application.py needs three
things:

- it must have the appropriate magic "hash bang" line as the first line of
the file;

- it must be flagged as executable;

- it must be located somewhere on the executable PATH.


I'm not sure what the Windows equivalents to that are.




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list