4

New to Python. I get the following error on doing a python --version on my GitBash. ...Appdata/Local/Microsoft/WindowsApps/python3: Permission Denied

Based on some answers on this forum I turned off the App execution aliases for python. Doing this deleted the two "stubs" python.exe and python3.exe from my Windows App folder and resulted in another error of No such file or directory to my python --version on GitBash.

I am a novice to python so it gets annoying to be stuck at the installation itself. What am I missing here ???

It's December and all these updates from Microsoft I assume has still not fixed this issue. Or?

user12589647
  • 79
  • 1
  • 1
  • 5
  • The app distribution of Python is not compatible with gitbash -- or any other Cygwin/MSYS based shell -- because Cygwin unsuccessfully tries to stat the executable. The links in WindowsApps are appexec reparse points, which have no support in the I/O manager. Trying to reparse them in `CreateFile` always fails. `CreateProcess` is designed to handle this failure by opening the reparse point to read app-related security attributes, which it uses to create/impersonate a modified token that's allowed to execute the real executable. – Eryk Sun Dec 26 '19 at 18:51
  • Windows could be handling this better to allow for a standard user to stat metadata about the real executable, while still restricting execution without the required security attributes in the token. As is, Cygwin/MSYS itself will have to learn how to handle this case better. – Eryk Sun Dec 26 '19 at 18:54
  • Until then, if you need to use gitbash you should use a regular Python installation downloaded from python.org, and enable the installer's option to update `PATH` if you don't know how to do it yourself. (But if you're learning a programming language without already understanding basic OS administration, then you're putting the cart very far before the horse.) – Eryk Sun Dec 26 '19 at 18:55
  • Thanks for your response Eryk Sun. Although I am not new to programming. But very new to Python and Shell scripting too. About your response: I was checking the python version after I downloaded and installed it from the website itself. I downloaded the latest 3.8 version. The reason I was referring to the Windows installed python.exe was because it was talked about on this forum for the same topic. Otherwise my installation is fresh off the website. Yes I see adding my installation path to the PATH variable as the only option I guess. – user12589647 Dec 28 '19 at 20:10
  • **See Also**: ["Permission Denied" trying to run Python on Windows 10](https://stackoverflow.com/q/56974927/1366033) – KyleMit Jun 06 '20 at 15:29

3 Answers3

13

To fix this Problem you need to install the required Python-Windows-Version (In my case it was 3.9). Then you search for Edit environment variables for your account in the startmenu. Open up the PATH-Variable and move the PATH for %USERPROFILE%\AppData\Local\Microsoft\WindowsApps below the PATH of your Python-Installation.

This image shows the edited PATH-Variable

Now you enter manage app execution aliases into the windows search and deactivate the 2 Entrys for python there.

This image shows the deactivated python*.exe files in Settings -> App execution aliases

The last thing you need to do is to open your Python-Installation-Folder. This folder is usually at %USERPROFILE%\AppData\Local\Programs\Python\Python39 (If you're using Python 3.9) Don't forget to change the path to your Python-version (e.g. Python38).

Copy the file python.exe in the same directory and rename the copy to python3.exe. So you have both python.exe and python3.exe in the installation-folder.

This image shows the copied python3.exe in the folder of the python installation

You can find a similar solution to this problem here

Holt
  • 174
  • 1
  • 8
  • 2
    Wow, this was quite the adventure but sure enough it worked for me. I was using VScode trying to use `git filter-repo` and until I did these steps, I had no luck. Thank you. – Mark May 20 '21 at 22:31
  • 1
    don't copy the executable, make a symlink using `mklink python3.exe python.exe` instead, run the command in the `Command Prompt` with admin rights – CervEd Jun 02 '21 at 09:31
2

Solved: Python commands won't work on mintty. I did a python -i to enter the python mode Another option is to do a 'winpty python.exe'

user12589647
  • 79
  • 1
  • 1
  • 5
  • This answer was way quicker than the accepted one. Even though you do have to type a longer command. – Dincio Jan 02 '22 at 21:07
-3

simply uninstall the old one and install the new one you just downloaded. git team has already solved the issue is the last option when installing just check it to use it with python and other programs.