2

I am facing an issue where I can run Python seamlessly within Visual Studio Code and the Python terminal. However, when I try to create a Python virtual environment using the command python -m venv venv or check the Python version with python --version, I encounter the following error message:

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

I have attempted to resolve this by uninstalling and reinstalling Python multiple times, and I even downloaded it from the Microsoft Store as prompted. Despite Python being successfully installed and capable of executing Python commands, the Command Prompt does not recognize its presence on my computer.

I even created a new folder containing a blank Python file and attempted to create a virtual environment from there, but the issue persists. My research into this problem has not yielded any conclusive explanations. Can anyone provide insights into why this might be happening?

2
  • Visual Studio Code can use /full/path/to/python. If you run code outside IDE you may also need to use /full/path/to/python, or you have to add /full/path/to (without python) to variable PATH and system will know where to search python when you run it without full path. Commented Oct 11, 2023 at 19:52
  • @JialeDu I solved the issue, although I'm unsure about the exact reason. Initially, I deleted all versions of Python and attempted to reinstall it using Microsoft's installer, but that didn't work. I went back to it a few days later, and it was fixed. I'm assuming it had something to do with just restarting my computer after getting rid of the non-working python versions. Commented Nov 11, 2023 at 18:03

4 Answers 4

2

You can try using the full python path as the command. For example E:\Desktop\project\.venv\Scripts\python.exe --version.

Of course, you can also add the environment variable path. You can also check this setting when installing python.

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

1

You may need to add Python to your PATH environment variable. See https://datatofish.com/add-python-to-windows-path/ .

Comments

0

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

I am using Windows 11. I 've got this error, but i tried to resolve this issue by reinstalling python by python website. But vs code getting same error. Finally I resolved that by typing Microsoft store in windows search. Then type the python in Microsoft store search and select the python version and get it. After downloading then it was resolved.

Comments

0

When you first install Python, the first command box should ask if you want to "add python to PATH", make sure that box is checked. I had that same error and this fixed it.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.