运行Python文件时提示‘Python’不是内部或外部命令的问题求助
Hey there! Let's work through why your Python command isn't being recognized, even after trying some fixes. Here's a step-by-step breakdown to get it sorted:
1. Locate Python 3.10's actual installation directory
The path you found in the Start Menu (C:\Users\faiqf\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Python 3.10) is just the shortcut location—not where the actual python.exe executable lives. Here's how to find the real path:
- Right-click the Python 3.10 icon in your Start Menu and select Open file location
- In the folder that opens, right-click the Python shortcut again and choose Properties
- Look at the Target field—this will show you the full path to
python.exe(it should look something likeC:\Users\faiqf\AppData\Local\Programs\Python\Python310\python.exe). Copy the folder part (withoutpython.exeat the end) for later.
2. Update your PATH environment variable
Right now, your PATH includes C:\Python34\Scripts (for an older Python version) but no entry for Python 3.10's main directory (where python.exe is stored). Here's how to add it:
- Right-click This PC → Properties → Advanced system settings → Environment Variables
- Under System variables, find the
Pathvariable and click Edit - Click New and paste the Python 3.10 folder path you copied earlier (e.g.,
C:\Users\faiqf\AppData\Local\Programs\Python\Python310) - Click New again and add the Scripts folder for Python 3.10 (it's inside the main folder, e.g.,
C:\Users\faiqf\AppData\Local\Programs\Python\Python310\Scripts) - Move these new entries to the top of the Path list (so Windows prioritizes Python 3.10 over the older Python 3.4)
- Click OK on all windows to save changes
3. Restart your command prompt and test
Environment variable changes don't take effect in already open cmd windows. Close any existing cmd windows, open a new one, then run these commands to check:
python --version py --version
The py command is the Windows Python Launcher, which should automatically detect your installed Python versions if the PATH is set correctly.
4. If all else fails: Reinstall Python with PATH enabled
If you still can't find the correct path or the above steps don't work, try reinstalling Python 3.10:
- Grab the Python 3.10 installer again
- Run the installer and make sure to check the box that says Add Python to PATH before proceeding with the installation
- Choose the Modify option if you're reinstalling over an existing setup
内容的提问来源于stack exchange,提问作者Faiq

