7

I've installed Python's latest version. However, when I write in command prompts

python --version

I get:

Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.

I tried downloading it directly from the Microsoft Store, however, the problem with that was that I could not very easily create a path for it and ran out of skills.

Anyways I'm trying to get Robot Framework to run just for fun, I'm a complete beginner as you can probably see. What should I do to fix this?

haileek
  • 71
  • 1
  • 1
  • 2
  • 2
    Does this answer your question? [Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings](https://stackoverflow.com/questions/65348890/python-was-not-found-run-without-arguments-to-install-from-the-microsoft-store) – Gino Mempin Feb 28 '21 at 12:48
  • Might be this answer will help you: https://stackoverflow.com/a/65496777/6280135 – Maninder Apr 04 '23 at 14:50
  • 1
    Does this answer your question? [CMD opens Windows Store when I type 'python'](https://stackoverflow.com/questions/58754860/cmd-opens-windows-store-when-i-type-python) – starball Jun 07 '23 at 02:51

7 Answers7

3

You have to add the path of Python to the environment of your system.

For more details refer: How to add Python to Windows PATH

2

I had the same issue, it happed that i just had go to Windows settings and search for manage app Execution Aliases.

I had both python and python3 installed, so I turned off the one I didn't want to use. Then it worked fine. Seems like the both were under same name "App installer"

enter image description here

NOTE:
Comment from here

The python.exe and python3.exe app execution aliases are part of the Microsoft.DesktopAppInstaller UWP app. This application cannot be removed (the AppX package's NonRemovable property is true). Removing the python.exe and python3.exe files (actually NTFS reparse points) from %LOCALAPPDATA%\Microsoft\WindowsApps is functionally equivalent to toggling the app execution alias in the Settings app. Unfortunately, their removal is not noticed by the Settings app, as it uses its own persistence (via Windows.StateRepositoryPS.dll) to keep track of the toggle state.

not2qubit
  • 14,531
  • 8
  • 95
  • 135
Afeez
  • 21
  • 1
1

I am pretty new to visual studio code and I tried to follow all of the advice with absolutely no luck.

I had uninstalled python and reinstalled and was about to give up. Then I uninstalled and when I reinstalled I noticed at the beginning of installer ADD TO PATHwith a tick box there. I ticked it, installed, restarted and wallah Everything worked like it should.

So simple and so hard to get there!!!!!!

0

When Installing Python on Windows, be sure to run the installer by right-clicking and selecting 'Run as Administrator' then select the add Path check-box in the installer for it to work.

The first time I installed Python without 'Run as Administrator' and checked the box, but the Path was not setup correctly. So be sure to 'Run as Administrator' for the process to work as expected.

Sage
  • 1
0

I was running into the same issue. I'm currently on the non-admin account on this Windows computer. Unsure if it was everything I did differently this time or not, but:

  1. I uninstalled both Python and Python launcher from the uninstall/Apps & features settings page.
  2. right-click > Run as administrator on the downloaded .exe
  3. Instead of the default install, Custom install, add to PATH
  4. Install for all users (note that this changes the install location below; it went from a user folder to a C: one).

I was able to use it after that!

-1

How to add Python to Windows PATH

There are few ways in which you can add Python to Windows PATH. In this guide, I’ll share with you two methods that you can use to add Python to Windows path:

Via the installation of a recent version of Python Manual entry of the paths But why would you want to add Python to Windows path in the first place?

Well, if you try to install a Python package using PIP for example, you may get the following error in the Windows Command Prompt:

‘pip’ is not recognized as an internal or external command, operable program or batch file

To overcome this error, you may apply any of the two methods described below.

Method 1: Install a Recent Version of Python You can easily add Python to Windows path by downloading a recent version of Python, and then checking the box to Add Python to PATH during the installation.

Before you proceed, you may choose to uninstall your previous version of Python if needed.

In my case, the latest version of Python that was available to download was version 3.7.2.

In the Python installation box, just check the box to add Python to PATH as below:

How to add Python to Windows PATH

Finish the installation, and you should be good to go.

Alternatively, you may manually add the paths into the Environment variables.

Method 2: Manually add Python to Windows Path If you wish to stick with your previous version of Python, you may apply the steps below to manually add Python to Windows path.

Note that I’ll be using Windows 10 to demonstrate the steps, but similar principles would apply for previous versions of Windows.

Step 1: Navigate to the Windows Environment Variables screen To navigate to the Windows Environment Variables screen, where you can add/edit your paths, simply right click on the ‘This PC‘ icon. Then, select ‘Properties.’

This PC - Windows 10

Next, click on the ‘Advanced system settings‘

Advanced system settings

Finally, click on the ‘Environment Variables…‘

Environment variables

That should take you to the Environment Variables screen, where you can add/edit your paths.

Click on ‘New…‘ to add the ‘Path’ variable (note that if your ‘Path’ variable already exists, then click on ‘Edit…’ instead):

add Python to path

You should then see the following box, which will allow you to add/edit variables:

New User Variable

Before you type any values, you’ll need to locate the relevant Python paths. The paths that you’ll need to get are:

The Python application path, which is the folder where you originally installed Python; and The Python Scripts path. The Scripts folder should be located within the Python application path. Here is how my Python application path looks like:

Python application path

And this is how my Python Scripts path looks like:

Python Scripts path

Now let’s fill the New User Variable box that you saw earlier:

New User Variable

For the Variable name, type ‘Path‘.

For the Variable value, copy the full Python application path, then use semicolon (as highlighted in yellow below), and finally copy the Python Scripts path.

This is how my Variable value looks like:

C:\Users\Ron\AppData\Local\Programs\Python\Python37-32;C:\Users\Ron\AppData\Local\Programs\Python\Python37-32\Scripts

Put all the values together in the New User Variable box:

New User Variable - Windows 10

Press ‘OK’ and you would then see your new Python Path under the ‘User variables’ section. Don’t forget to press ‘OK’ again so that the changes will get implemented.

How to add Python to Windows PATH

That’s it! You just added Python to the Windows Path.

You’ll now be able to install Python packages easily, by opening the Windows Command Prompt and then typing:

pip install package name

For example, to install the pandas package, simply type ‘pip install pandas’ and then press Enter:

How to add Python to Windows PATH

Similarly, you may upgrade PIP by typing the following command:

python -m pip install --upgrade pip

Nirajan Mahara
  • 1,644
  • 9
  • 7
-1

As of June 3, 2023, with Python 3.11.3 installed on Windows 11 Pro Version 22H2 (OS Build 22621.1702), I observed the following behaviors, one that creates the behavior in the OP and one that does not:

  1. In Windows Explorer, when I right-click on a folder and choose Open in Terminal, the issue with Python not being found occurs every single time, even with the seemingly simple python --version.
  2. If I open Windows Terminal (or CMD prompt or PowerShell prompt) and then navigate to the very same folder, both python --version and (for example) python hello.py will run.

In both cases, the observed Windows PATH using PowerShell in the form of $env:path -split ';' | more includes both of the following:

  1. C:\Program Files\Python311\Scripts\
  2. C:\Program Files\Python311\

What this tells me is that right-click, Open in Terminal within Windows Explorer lacks something critical besides PATH information.

Taking the time to first open a CMD or Terminal or PowerShell prompt and then navigating to the directory where your .py file is located is the magic fairy dust that makes python work at the command prompt level in Windows 11 (and probably all the way back to 8.1).

And, before you ask, all my various IDE's such as PyCharm 2023.1.2 (Build #PY-231.9011.38, built on May 16, 2023) and Visual Studio Code 1.78.2 (user setup) work just fine with Python files.

This is something quirky with Windows 11 and an apparent bug in the way right-click Open in Terminal fails to work correctly when passing along the proper environment information to the instance of Windows Terminal it opens.

user3785010
  • 1,029
  • 1
  • 10
  • 11
  • Ok, you basically re-analyzed the problem, but didn't provide a solution. In addition OP originally asked about CLI operation, not run from windows explorer. – not2qubit Aug 14 '23 at 13:20