Python not found by command prompt

I have installed Python in Windows 11 and saved a small script called unicode.replacer.py

In the command prompt, in the correct directory, when I attempt to execute: python unicode.replacer.py
command prompt reports: Python was not found.

Any suggestions welcome.

Hello, if you install Python from official installer you need to add Python executable to PATH,
This article have good explanation for that

1 Like

Thanks for the response.
I followed the instructions to the letter, located the Python executable at
C:\Users\esper\AppData\Local\Programs\Python\Python312\python.exe
and pasted it in and did everything else as instructed. No luck, command prompt still can’t find Python.

We get this issue all the time.

Please read:

Please keep in mind that the PATH should contain the folder where Python is located - not the path of the executable itself. This is an issue with understanding Windows, not a Python issue.

In the future, I plan to have a more specific, organized Q&A for this issue on Codidact.

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

py unicode.replacer.py

You have to update your windows PATH variable to add 3 directories. Just add this to the end of your path: c:\users\chuck\AppData\Local\Programs\Python\Python312\;c:\users\chuck\AppData\Local\Programs\Python\Python312\Lib;c:\users\chuck\AppData\Local\Programs\Python\Python312\Scripts

I had to add all 3 dirs to get PIP and the modules to work correctly.

Fix your path with a custom autoexec.bat

I also have a DOS cmd shortcut which puts me in my Python projects dir, and calls a custom c:\apps\autoexec.bat file.

In the shortcut this goes in the Target field: C:\Windows\System32\cmd.exe /k c:\apps\autoexec.bat

This will launch cmd.exe and execute the autoexec.bat file and stay in the cmd window.

My partial autoexec.bat file also sets up the PYTHONPATH just in case.

set PYTHONPATH=c:\users\YOURNAME\AppData\Local\Programs\Python\Python312

echo Path=%path%
echo PYTHONPATH=%PYTHONPATH%

Fix your path in Windows system config

  1. Go to Control Panel.
  2. Search for “path” without the double quotes.
  3. You should see something like “system” or “Edit the system environment variables”. Click that.
  4. A window will pop up. Cick the Advanced tab.
  5. On the bottom of the Advanced tab click “Environment variables” button.
  6. Under the area “User variables for YOURUSER” click the entry for Path, then click Edit button.
  7. Another window will pop up.
  8. Click New and add 3 entries total, one for each path I put above. Windows will string them together for you.
  9. Click OK. Click OK on Environment Variables.
  10. Close the System Properties window.

In my c:\apps directory I also have the TED.exe editor, Tiny editor, which is very small, and super handy packed with features! Get it here: TED Notepad

1 Like

I don’t see “py” for Python 3.12 in any directory. It was on Python 3.11 though. So I ended up making a py.bat file I put in the same dir as python.exe.

@echo off
rem This assumes you have set up your PATH and PYTHONPATH variables.
echo Running py.bat
rem Next line adds in all parameters you pass in. It's percent and star.
python %*

On Python 3.12 one must use the command python (no parameters) to go into the interactive mode as well.

Any idea where “py” is for Python 3.12 on Windows 11 Home?

In C:\Windows, like the documentation (last link I gave you) says. The entire point of it is that there is only one copy even if you install multiple versions of Python (so that it can find one for you), and that it’s in a place that will always be on PATH (so that your PATH doesn’t need to be modified).

You should not make your own wrapper for this, and the wrapper you show accomplishes nothing - you’re expecting Windows to look for it in the same place that you want it to find Python, using the same logic.

Yes, whenever python finds a Python interpreter, python without parameters gives you the interactive prompt for that interpreter. Similarly, py without parameters gives you the interactive prompt of whichever Python interpreter py finds. There is nothing version-specific about this (except that py hasn’t existed forever). py also has its own command-line options that control how it looks for Python, and then it forwards additional options to the Python that it finds.

1 Like

Thank you. My path is not setup to look there. No wonder cmd.exe couldn’t find it. I’ll fix my path.

Cool! I see you made an edit and your post updated automagically. This is great forum software!

EDIT: I meant that when I open a cmd.exe prompt, I run an autoexec.bat file which sets the path and c:\windows is not in that particular path. I wonder if this overrides the user and system path variables. My c:\windows was in the SYSTEM path variable, but not my user path variable until I added it.

“py” works for me now in a cmd.exe prompt.

That can’t possibly be right. If your PATH does not include C:\Windows already then I should expect multiple things to go wrong while trying to boot the computer. (You should be aware that there are separate system- and user-level settings for PATH.)

Have you tried to run py?

Open a Command Prompt or PowerShell window and type py.

Apparently there’s a time limit on editing old posts… makes sense, but means I need a new post here to add the relevant corresponding Codidact links (I’m biased, of course, but I think they’re clearly higher quality):

Karl, in a couple places you mention that the launcher is always installed for all users in “%SystemRoot%”. Note that for a while now the default has been to install it for the current user in “%LocalAppData%\Programs\Python\Launcher”. Thus the default installation doesn’t require administrator access. When installed for the current user, the launcher’s directory is always added to the user “PATH”.

Note that if a user has a standard user account, instead of an administrator account, then running with administrator access via OTS logon won’t have the user-installed launcher available in “PATH”. Even if it were available, the user installations of Python wouldn’t be visible to the launcher.

Personally, I use a standard user account for almost everything, except I use the builtin “Administrator” account for system administration and installation of applications. I recommend against per-user installations, unless you have no choice because your machine is locked down by your employer or institution.

Wait, even when installed for all users? How do other users get to use it, then?

No, it’s just for a default installation for the current user. If you install for all users, then the launcher gets installed in “%SystemRoot%”.

This worked well for me, thanks!