Why doesn't the command Python not do anything in Command Prompt? - python

The Command Prompt does not do anything when I use the Python command to execute a module. It does not even do anything when I use it at all; it just pretends that I did not do anything, and goes back to the current working directory. Attached is a screen shot for clarity.

Apparently, if you call python from Windows' Command Prompt (at least with my home computer), it will look for any python version installed using Windows Store, so if you just type python, it will open the Windows Store for you to install.
If you have Python installed, try to call full path to executable or try to add the path containing your Python executable (in my case, C:\Python38) to the system environment variable PATH:
Search for "Edit the system environment variables".
Click the Environment variables... button (in the Advanced tab)
Edit PATH and append ;C:\Python27 to the end (substitute your Python version)
Click OK and reopen cmd for change to take effect.

Update.
I simply uninstalled and reinstalled Python. Once I did that, the program works as it should in CMD.

If you have python already installed, you should just be able to type 'python' alone then press enter. It should then give you a space to execute python code. It could be simple fix, but if not it's still worth a shot.

When its the first time you're going to install python on Windows it shows you the option Add to path unchecked, so you just need to check that option and install python, you can uninstall python and installet again with the check, this fix the problem.

I just use the IDLE, it is the easiest way to run python scripts. Just open up IDLE and click on File < Open.. < and select your file. Then make any last minute changes and click on File < Save. Click on Run < Run Module (or F5) to run the python script. Done.
This is great for people that want to use python 2.7 or just don't want to install the python application from the Microsoft store.

Sometimes the order in which the PATH environment variable is set also matters; if the Windows store variable is before the path where Python is installed then the windows store will open when you type python.

Related

VSCode not selecting the correct python interpreter

I have a script that I need to run using a very specific python interpreter in my hard drive.
I am using vscode as the IDE and trying to select the python interpreter using the command palette.
However, since the concerned interpreter is not present, I manually search it.
However, even after that, it doesn't work as typing python in the terminal then opens the windows store for installing a python IDE. I also tried adding the interpreter's path to the environment variables but the problem still persists.
How do I solve this issue.
Thank You for the help.
The Python version you selected on VS Code only effects the editor. Right click to any file on the sidebar and select Open in Integrated Terminal. If your selected Python version is created with virtualenv it will activated and your python command works.
If not worked and you want a global Python version, you need to add Python path to your system variables to work python command. Check this:
https://geek-university.com/python/add-python-to-the-windows-path/
Btw I don't think your python.exe in FreeCad/bin directory is proper Python version
At the bottom left you can select the Python interpreter.
Here it shows you on -how to do that: Python Interpreter
Reason:
Your system environment path contains this: %USERPROFILE%\AppData\Local\Microsoft\WindowsApps.
Solution:
Open Window Search(Win) to find Manage app execution aliases. To turn off App Installer of python3 like this:
You can refer to this answer for more information.

Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings

I was trying to download a GUI, but the terminal kept giving me this error:
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
I'm trying to install it using this command:
python -m pip install --upgrade pip setuptools virtualenv
Check your Python version and be sure it is installed on your machine
Check the path environment variable
Go to -> "start" and type "Manage App Execution Aliases". Go to it and turn off "Python"
I was having the same issue and I fixed it by using the below method.
Copy two paths of Python
C:\Users\Maninder\AppData\Local\Programs\Python\Python39
C:\Users\Maninder\AppData\Local\Programs\Python\Python39\Scripts
These are the paths where your Python interpreter is installed. Now add this path into your environmental
variable. Put this path into System variable, not in user variable. I was using user variable, so I was facing the issue.
I have a solution for you. Make sure you check the path mark during installation. Then you need to go to Manage App Execution Aliases.
Simply go to your search bar and search for Manage App Execution Aliases. You will find the attached screen and you need to turn off App Installers as you see on the screen. Also, see the path,,, follow Maninder's answer.
Then you are good to go! :)
I had the same issue. In Windows CMD, only: py --version, works.
I tried adding the path on System variables, and it didn't work. If you are using PyCharm as I do, try to run all commands from the IDE's terminal. It usually is on the side bar where the Run and the Console is. If it is not, go to: menu View → Tool Windows → Terminal. It worked just fine for me.
You need to download Python from https://python.org. When in the installation, be sure to check the option that adds Python to PATH.
I haven't gotten this error before and have been using Python a long time, and then suddenly it showed up. I think that it is a result of a Windows update designed to steer you to their store.
In any case: to remedy the problem, go to Settings → app execution aliases → and turn "off" Python. (What they tell you to do, in other words). This should resolve the problem.
If you have installed Python successfully with add python path, ticked on, and have added
C:\Users\<user>\AppData\Local\Programs\Python\Python39
C:\Users\<user>\AppData\Local\Programs\Python\Python39\Scripts
to the path into System variables and have turned off the "aliases" and they all didn't work, you can simply use python instead of python3 in your cmd command.
Check the Aliases for App Execution in Windows. Search for Alias App in your Windows toolbar to find the UI for this. Try turning off anything Python related.
Try adding the following to your "Path" environment variable:
C:\Users\Default\AppData\Local\Programs\Python\Python37
C:\Users\Default\AppData\Local\Programs\Python\Python37\Scripts
Replace Python37 with your own version.
I solved this problem for Visual Studio Code with just writing "python" in the console:
python
After that, Microsoft Store opens automatically with the Python app:
And I just click Get.
And it all work!
All the previous answers are correct, but in my case, I was getting this, because I was not passing the version...
The fix is passing the version:
py.exe -3 your_program
If you're on Windows, you may want to use the Python installer, in Windows Marketplace.
I faced the same error while using Anaconda and trying to link the Python executable path in the command prompt.
It got rectified by going to Settings → App execution aliases → and turning "off" Python. Then again I had to set the path for Python in Anaconda and was successful in executing "python --version" command.
The same thing happened to me even after trying all the above-mentioned steps.
I just restart my system and it was working fine. Do it and if still doesn't fix the issue then make sure you have checked "add python ( any version ) to PATH" before installing Python.
If none of the previous answers are working, you can check if you have the Python executable in your program files.
Go to C:\Program Files and check if you have the Python application. If not, go to the python download website here and download the .exe file.
While installing you must select "Custom install" and select the location as C:/Program Files.
Install it and it should work now from anywhere. This worked for me!
To sincerely resolve this issue, do the following:
Uninstall the Python instance and reinstall it. Note: Make sure you check
"Add variable PATH".
On the command line, type:
python -m pip install --upgrade pip setuptools virtualenv
I got this issue when I used Visual Studio Code as the IDE, and Anaconda as my Python compiler. And you don't need to close the "app alias" in settings, but copy your python.exe to python3.exe in your Anaconda folder.
That happened to me. So, to fix it, you have to follow the following steps:
Uninstall the Python version you already installed.
Go ahead and open the installation file to reinstall it again.
Before hitting Install Now, make sure to tick the box in front of Add Python to path.
Go ahead and complete the installation procedure as usual.
Steps for installing Python
The problem is more subtle than it seems.
For example, if you are using Visual Studio Code on the bottom left, you should see Python X.X.X xx-bit (the X is the version).
If you click in there you will see where the IDE is getting the python.exe from.
Locate that folder into your file explorer and then just follow the answer that is saying to change the environments variables.
So copy the path where python.exe is and add it to the Path variable and do the same where the Script folder is (it is in the same directory where the python.exe is).
Then of course make sure your IDE is using the right Python.
None of the answers here worked for me. I did this and the error went away.
For Windows 11 which I was using, I reran the python-3.10.5-amd64.exe file from my downloads directory and then chose to modify the installation.
Then I followed these easy steps.
Make sure the PIP component is checked before proceeding to install.
Then check 'Add Python to environment variables' if it's not checked already.
Proceed to Install.
At this point, your error will be solved
If you already have the Python executable on your machine and you are getting this error in Windows 10, search for the Python executable and copy its path then copy the path in system variables. It worked for me.
to check in windows
py --version
or restart your pc first then put htis command again
I was also facing this issue after installing python, while running command
python --version in command prompt , error as:
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
So, i too added
the path in environment variable as shown, and it worked:

Python3 seems not to be recognized in VSCode

I had Python version 2.7.17 already installed on my machine. Recently I started coding in Python and I installed VS Code to make things easier. However once I opened VSCode and ran a simple Python Hello World program, VSCode terminal gave a warning saying that
Python 2 support has ended at January 1, 2020
which means the support has already ended and suggested to install the latest Python version. So I heeded the warning and installed Python 3.8.5 on my Windows machine. The installation was completed without any issue. Afterward, when I tried the command python --version on VSCode terminal, it correctly gave the output python 2.7.17. However, when I tried the command python3 --version to check if it was correctly installed, the terminal gave no output.
Since I am a beginner and the support for Python 2 has already ended, I would like to work with Python3 from now on. However, I don't mind Python 2 staying in the machine.
Is this something should I worry about? Or should I uninstall Python 2 completely (When I checked Control Panel both versions are list under currently installed programs)?
According to your description, you can change pythonpath in vscode and still keep python2.
I assume you are using windows system and if not, please let me know. The following is the solution:
open cmd and type: where python. There should be two path, copy it which is about python3.8.5;
press Ctrl+, to open setting.json and add an entry for python.pythonPath manually inside your User Settings:
Now you can press Ctrl+Shift+P and find the option select interpreter. Click it you'll find a interpreter list. After selecting new interpreter, it is necessary to press Ctrl+Shift+` to open a new terminal for further development.
About more detailed information about pythonpath and interpreter you can refer to using python environments in vscode.
The version of Python used depends on your environment, and PATH variable.
I think you need to select the correct Python interpreter. At the bottom of your screen, there should be something that says the Python version number. If you click it, you can get a menu to select the interpreter.
Alternatively, you can hit control-shift-p, type "python interpreter", then click "select python interpreter" option.
Finally, you can alter the default Python interpreter used by changing the User settings in VS Code. Hit control-shift-p, type "open settings", and select Open Settings (JSON). Add a key to the JSON file called "python.pythonPath", so that you have a line that looks something like this:
"python.pythonPath": "full/path/to/the/python/executable/you/want/python.exe",
You might be able to get a hint as to the path to use or available isntallations of python if you type where python or which python (depending on terminal/ OS in use).
Then you can save those settings. Restart VS Code. Hopefully now the correct interpreter is selected by default.

The Python executable is not recognized on Windows 10

I recently installed Python 3.6.3 on my device. When I type python in my cmd window, it gives me this error. I do have the PATH in the environment variables. Path Lists. This should normally fix it, but python is still not recognized.
I had the same problem, due to a stupid decision from Microsoft.
I had another line in my system path variable:
C:\Users\MyUserName\AppData\Local\Microsoft\WindowsApps
And Windows 10 put a python.exe file there that only redirected me to the Python page of the Microsoft Store:
Since this line was above my true Python path, typing python in the cmd prompt opened the Microsoft Store...
Solution:
Type App execution aliases in the Windows 10 search bar, and then uncheck the aliases for python.exe and python3.exe. More information is here.
The path to the Python executable needs to be in the System PATH variable. Note this is not the User PATH variable.
The OP had Python 3.6.3 installed in C:\Python\Python36-32, however a common default location for installation is in the users AppData\Local\Programs\ folder. This post will assume a Python 3.10 installation in this location. Please adjust as needed for your current Python version and path.
You can confirm the path from the command prompt by checking the Python executable directly from the folder.
cd %LOCALAPPDATA%\Programs\Python\Python310
python --version
This should print the Python interpreter version. For example, Python 3.10.4.
Add the following entries to the System PATH:
%LOCALAPPDATA%\Programs\Python\Python310 for the python executable
%LOCALAPPDATA%\Programs\Python\Python310\Scripts for tools such as pip
After adding the path to the System PATH variable, make sure you close and reopen any command prompts, so they use the updated PATH.
If it is still not working, as mentioned in the previous answers, then simply move up the path, as shown in the screenshot.
You get this error, because the python.exe path has not been added to the System environment variable. To do that, simply:
go to the path C:\Users\%Username%\AppData\Local\Programs\Python\Python37-32 which contains python.exe
copy the path and open System environment variables and in the variable section look for variable called Path. If not, create a new variable with Variable Name as Path and value as the copied path
Once you do that, close the window and simply open cmd. Type python and you should get something like this:
If you are trying to install the new Python version, python-3.9.6, then click the checkbox of Add Python 3.9 to PATH
This happens because the path doesn't exist in environment variables.
To fix this:
Rerun the installer
Choose Modify
In optional feature click "Next"
In advanced option tick the "Add Python to environment variables"
Install
All the answers on Stack Overflow_ about it were obsolete, so I decided to add this. The path variable that needs to be added is,
C:\Users\Username\AppData\Local\Programs\Python\Python36-32
Note that everyone may have a different Username.
If you are working with the command prompt and if you are facing the issue even after adding the Python path to system variable PATH:
Remember to restart the command prompt (cmde.exe).
I too was struggling with this issue, and everything was configured correctly. I installed and setup my system path variables as one would. And everything was fine. Then upon reboot windows would not recognize 'python' as a command as if it were unaware of the path variable. Double checked to confirm everything was still setup correctly (it was).
It only started to work again after I manually browsed to the directory in which python.exe existed, and ran 'python'. After that windows seemed to recognize my path variable and I could call 'python' from where ever need be. Very odd. Figured I'd share in case someone else runs into this.
For Python 3.6, there are actually two path entries. Also, it's best to use the %USERPROFILE% rather than hard coding it.
%USERPROFILE%\AppData\Local\Programs\Python\Python36
%USERPROFILE%\AppData\Local\Programs\Python\Python36\Scripts

How can I get python in the command prompt on Windows?

I have just installed Python on my Windows 7. I thought that after that I will be able to run python on the command prompt but it is not the case. After the installation I also found out that I can run the python command shell. This is nice. But what should I do if I want to save my program in a file and then I want to run this program (in Linux, for example, I typed "python file_name.py" in the command line).
You need to add the python bin directory to your path. Follow the instructions here and add c:\python26\bin to the path (unless you installed python in a non-default location).
Is python.exe in your windows path? Try to look at the PATH environment variable and see if the installation folder of python is listed there.
You need to update your environment variables to include the path to the Python executable.
On XP you can do this by right clicking on "My Computer" -> Properties and then going to the "Advanced" tab.

Categories