Re: Fwd: Python Question re Executing a Script (dn)

2022-05-02 Thread MRAB

On 2022-05-02 17:23, Dennis Lee Bieber wrote:

On Mon, 2 May 2022 20:33:02 +1200, dn 
declaimed the following:


Perhaps an MS-Win user can help the OP, please?


Not really -- at least from my viewpoint there is not enough
information to perform any diagnoses... Other than to recommend that, if
the OP initially posted to the list/newsgroup, they should ensure any
replies also go to the same (I don't respond to what should be group
replies that appear in my personal mail -- which is what the OP did for me
also).

{Hmmm, appears the quoted content is below your signature block, and my
client doesn't quote standard signatures and below... time for some nasty
cut}


From: Brent Hunter 
Date: Mon, 2 May 2022 00:30:22 +




I was recently running a Windows 10 machine and I believe it was running Python 3.8.  All I did was create a batch file 
titled Start-AIG.bat which simply contained the following: "pythonw AIG.py".  It started a python program 
titled "AIG.py" and the Python dialog box was displayed on my screen, running all day and night.  I set up 
Windows to run this batch file upon startup and it worked fine.  I remember having to do a bunch of research before I 
learned that I needed to put "pythonw AIG.py" in the batch file as opposed to "python AIG.py".




[snip]
FTR, I've already posted the suggestion to try the Python Launcher 
"pyw", and the OP replied off-list that it worked.

--
https://mail.python.org/mailman/listinfo/python-list


Re: Fwd: Python Question re Executing a Script (dn)

2022-05-02 Thread Dennis Lee Bieber
On Mon, 2 May 2022 20:33:02 +1200, dn 
declaimed the following:

>Perhaps an MS-Win user can help the OP, please?

Not really -- at least from my viewpoint there is not enough
information to perform any diagnoses... Other than to recommend that, if
the OP initially posted to the list/newsgroup, they should ensure any
replies also go to the same (I don't respond to what should be group
replies that appear in my personal mail -- which is what the OP did for me
also).

{Hmmm, appears the quoted content is below your signature block, and my
client doesn't quote standard signatures and below... time for some nasty
cut}

>From: Brent Hunter 
>Date: Mon, 2 May 2022 00:30:22 +
>

>I was recently running a Windows 10 machine and I believe it was running 
>Python 3.8.  All I did was create a batch file titled Start-AIG.bat which 
>simply contained the following: "pythonw AIG.py".  It started a python program 
>titled "AIG.py" and the Python dialog box was displayed on my screen, running 
>all day and night.  I set up Windows to run this batch file upon startup and 
>it worked fine.  I remember having to do a bunch of research before I learned 
>that I needed to put "pythonw AIG.py" in the batch file as opposed to "python 
>AIG.py".
>

What in particular is a "Python dialog box"? Python doesn't, of its
own, have dialog boxes. Add-on libraries: Tkinter, wxPython, the win32
extensions, et al. allow one to code scripts that produce dialogs, but the
dialogs are specific to the library.

"pythonw" is the name of the interpreter meant for use with programs
that do not use console I/O -- IOW, pure GUI (one of the aforesaid
libraries).

Normally such programs are given the extension .pyw rather than .py --
and (at least on my system), .pyw files are automatically associated with
pythonw. Just providing the script name with extension is sufficient.
Though there is the matter that giving said name in a command line prompt
means one still has a console active. .pyw files are meant to be started
from the file explorer by double-clicking on them, and one doesn't want to
have a console window popping up if it is never used (which is what happens
if one double-clicks on a plain .py file).


HOW did you "set up Windows to run this batch file upon startup"?

Windows used to support (and still does if
https://www.thewindowsclub.com/startup-folder-in-windows-8 is correct
[ignore the -8, the site is updated for 10/11]). This is per user start up
(unless one uses the "all users" path). The Windows task scheduler also
allows one to create tasks that run on a schedule -- said schedule
including options for specific user logging in, any user logging in,
computer start-up, etc. The scheduler is probably the recommended way to
set up things.


>However, my old windows 10 desktop crashed and I have a new Windows 11 
>machine.  I installed the latest stable version of Python, which is 3.10.  
>Now, when I try to execute the same batch file, it doesn't launch the app.  It 
>could be because I'm using Windows 11 or could be because I now have a newer 
>version of Python.
>
>With this additional information, do you have any ideas what I should do to 
>get the Python script running in the same way I had it running before?

As I stated above -- insufficient information.

Is Python installed for all users or just one?
Is "pythonw" on the system PATH?
Is the script meant to only run for one user or any user?
How was the script configured to start?
Is the script in a valid directory (I believe in a previous post it was
mentioned that you had the script in the directory used for per user
START-MENU entries; that is not meant for user files!).

My first approach would be to open a console and run the script
manually (not the BAT file) -- does any error message appear in the
console? Running using pythonw suppresses console, error messages would be
lost -- GUI applications are expected to trap any runtime errors and either
write to a log file or pop-up a dialog for them.

Then, after getting it to run in a console, I'd try it by
double-clicking on the file (rename it to .pyw so you get the no-console
interpreter). If Windows says it doesn't know how to run .pyw, it implies
that there is no file association set up in Windows telling it how to run
that extension.

NO BAT file should be required for a one-liner that does no parameter
substitution.

If using the "startup" directory method, create a shortcut for the
script (right-click, drag, create shortcut here). Right-click/Properties.
If you don't have associations set to run that extension type, prefix the
Target box with the path to the python(w) executable. Move the shortcut to
the proper startup directory -- Note that if you put it in the all-users
startup, you have to make sure that the script and shortcut themselves are
not in protected (single user) locations.


Fwd: Python Question re Executing a Script (dn)

2022-05-02 Thread dn
Perhaps an MS-Win user can help the OP, please?
-- 
Regards,
=dn--- Begin Message ---
Hello dn,

Thanks for your reply.  My apologies, I should have provided more background 
information.

I was recently running a Windows 10 machine and I believe it was running Python 
3.8.  All I did was create a batch file titled Start-AIG.bat which simply 
contained the following: "pythonw AIG.py".  It started a python program titled 
"AIG.py" and the Python dialog box was displayed on my screen, running all day 
and night.  I set up Windows to run this batch file upon startup and it worked 
fine.  I remember having to do a bunch of research before I learned that I 
needed to put "pythonw AIG.py" in the batch file as opposed to "python AIG.py".

However, my old windows 10 desktop crashed and I have a new Windows 11 machine. 
 I installed the latest stable version of Python, which is 3.10.  Now, when I 
try to execute the same batch file, it doesn't launch the app.  It could be 
because I'm using Windows 11 or could be because I now have a newer version of 
Python.

With this additional information, do you have any ideas what I should do to get 
the Python script running in the same way I had it running before?

Thank you!

Brent

-Original Message-
From: Python-list  On 
Behalf Of dn
Sent: Saturday, April 30, 2022 5:48 PM
To: python-list@python.org
Subject: Re: Python Question re Executing a Script

On 01/05/2022 10.37, Brent Hunter wrote:
> Hello,
> 
> I just purchased a new Windows 11 computer and installed Python 3.10.4 (64 
> bit).  I can't figure out from your documentation, how do I:
> 
> 
>   1.  Run a python script that is located in the same directory ( 
> C:\Users\Brent\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Python 
> 3.10 )
> 
> 
>   1.  How do I automatically run a python app at Windows startup?
> 
> Thank you!
> 
> Brent Hunter


Please start with https://docs.python.org/3/using/windows.html

-- 
Regards,
=dn
-- 
https://mail.python.org/mailman/listinfo/python-list
--- End Message ---
-- 
https://mail.python.org/mailman/listinfo/python-list