Hello --- I'm already confused

Hello!
I’ve never worked with Python but I downloaded it and installed it (Windows 11) so I could run a Python program that was given to me by a chip manufacturer. The Python program uploads an executable into a micro-controller board over a USB and also acts as a terminal communicating with the system code on the board. It is supposed to be called from a batch file. The batch file runs an assembler and linker to create the executable, then runs the Python uploader with the file name and some command-line options. The batch file aborts with a message that the uploader program:
“is not recognized as an internal or external command, operable program or batch file.”
Apparently Python is not in the path. In the old days, we had an autoexec.bat file that had a PATH command, so it was easy to put a program in the path. I don’t know how to do this now though.

I looked at the properties for the Python program and it opens with Python. If I double-clock on it I see the command window do something, but it closes before I can see what was done. Most likely it ran the Python program and the Python program aborted with an error message because it hadn’t been given a file to work with or any command-line options.

This is really a question about Windows, not Python, but it seems to me that the Python installation should have put Python in the path.

any help is appreciated — Hugh

You haven’t said what exactly it’s not recognising.

How is the uploader program run?

Does the line in the batch file say something like:

python path\to\uploader.py

Is it complaining that it can’t find python?

If yes, try changing that line to:

py path\to\uploader.py

On Windows, it’s recommended that you use the Python Launcher py.

Hello,

per this:

if you have a Python file (filename.py), you can’t open it by double-clicking on it as you would most other files. To open a .py, you have to open it with an editor. As you say, that you downloaded Python, open the editor then go to: File > Open. Go to the location where your .py file is located and select it to open it.

You can run the file from the editor or run it from the command prompt as per @MRAB.

Okay, I used PY and now Python is running the Python program using the filename and command-line options. :slight_smile:
Now my problem is that the source-code line INPORT SERIAL aborts with the message:
“ModuleNotFoundError: No module named ‘serial’”
Do you have any idea where I might obtain this? The chip man who gave me the file likely has it, but I don’t want to continue bothering him with basic questions.

— Hugh

That means that your Python script depends on an external package module.

In the command prompt, type the following:

pip install serial

or

py -m pip install serial

If you get additional similar exceptions, repeat for the other module packages to download them.

I tried PIP and it aborted like this:

WARNING: Failed to write executable - trying to use .deleteme logic
ERROR: Could not install packages due to an OSError: [WinError 2] The system cannot find the file specified: ‘C:\Python310\Scripts\futurize.exe’ → ‘C:\Python310\Scripts\futurize.exe.deleteme’

WARNING: You are using pip version 21.2.4; however, version 25.0.1 is available.
You should consider upgrading via the ‘C:\Python310\python.exe -m pip install --upgrade pip’ command.

I tried your other suggestion and that got past the attempt to import collected files, so the Python program seemed to compile okay.. Then, when the program ran, it aborted like this:

Traceback (most recent call last):
File “C:\wdc\W65C02SXB\02EDU_GettingStarted\EDU_GettingStarted\ASM\wdc_uploader_term.py”, line 44, in
from serial.tools.list_ports import comports
ModuleNotFoundError: No module named ‘serial.tools’

The first error message occurs because pip does not have permission to write in that location, while it is trying to add libraries to your installation of Python.

The warning about upgrading pip can usually be ignored, and I think if you tried to upgrade now, you’d run into the same permissions problem anyway.

Everything after that could be a consequence of not being able to install serial.

We can see from the error message that pip is running with Python 3.10 installed in the root of C:

This is an old version, and an odd place, considering you say you just downloaded and installed Python. When I install, I believe I do a “user” installation (there’s a “just for me” tick-box, I think) and so the files end up in my profile, which of course I can install to. Maybe you explicitly chose an old version and installed it there as an admin. Or maybe py is pointing to an old version on your disk.

If you launched pip with py -m pip, then it means py is still defaulting to that installation that apparently you are not allowed to change. You can ask what versions you have with py --list and the * in the listing marks the default version it will use. I get:

PS vsj> py --list-paths
 -V:3.13 *        ...\AppData\Local\Programs\Python\Python313\python.exe
 -V:3.12          ...\AppData\Local\Programs\Python\Python312\python.exe
 -V:3.11          ...\AppData\Local\Programs\Python\Python311\python.exe
 -V:3.10          ...\AppData\Local\Programs\Python\Python310\python.exe
 -V:3.9           ...\AppData\Local\Programs\Python\Python39\python.exe
 -V:3.8           ...\AppData\Local\Programs\Python\Python38\python.exe
 -V:3.7           ...\AppData\Local\Programs\Python\Python37\python.exe
 -V:3.6           ...\AppData\Local\Programs\Python\Python36\python.exe
 -V:3.5           ...\AppData\Local\Programs\Python\Python35\python.exe
 -V:2.7           C:\Python\2.7.18\python.exe

Hmm. I have been messing with Python for a long time. I don’t use py all that much as long before it matured I wrote my own way of switching versions. I don’t know how one changes the default, but it seems to be the last installed or latest. The quick way to find out which version you’re about to use is:

py --version

By the way, when you quote code or error messages, enclose them in three back-ticks as explained here. And there are formatting elements that will allow you to

avoid shouting

when you don’t mean to. Unfortunately, it’s the Python comment character, so it happens a lot.

You almost certainly want to install pyserial, not serial. The former package provides a serial bus interface, the latter is a json serialization library.

2 Likes

Still does (although is set in two parts, system and user), and this may be a part of the solution if py cannot ultimately be coaxed to work: How To Add/Edit Path Environment Variable In Windows 11

This worked. Thanks! :smiley: