vscode.py icon indicating copy to clipboard operation
vscode.py copied to clipboard

Python was not found

Open ashrauma opened this issue 2 years ago • 5 comments

I get an error when I run my function using Shift+Command+P. This is expected since my Python is not globally installed and comes from a virtualenv. How can I define path to Python?

An Error occurred in the python script: Python was not found c:\Program Files\Microsoft VS Code\1.58.2\resources\app\out\bootstrap-fork.js:5
An Error occurred in the python script:  but can be installed from the Microsoft Store: ms-windows-store://pdp/?productid=9NJ46SX7X90P

ashrauma avatar Aug 17 '21 14:08 ashrauma

More info, the problem is in build/extension.js file.

Solution: Get current activated virtualenv in VSCode and use that python to run python. Else get python from global environment.

ashrauma avatar Aug 17 '21 17:08 ashrauma

Will fix this soon 👍

CodeWithSwastik avatar Aug 26 '21 02:08 CodeWithSwastik

Any updates on this? I am building a vscode extension that needs the environment set in vscode. I'm probably going to hack together a solution so I can continue building this out.

I'm happy to contribute to a solution as well. If you want to give me a broad explanation of how you would like to approach this, I can work through it.

Nicholas-Schaub avatar Dec 21 '21 03:12 Nicholas-Schaub

I think I actually figured out how to resolve this. It comes with only a few minor code changes. It basically works like this:

  1. Get the path the current active environment path from the vscode-python extension api https://github.com/microsoft/vscode-python

  2. When running extension.py, replace python3 with the path to the active python environment.

This seems to work. One other thing I've added is changing the working directory to the workspace directory prior to running the script. The main reason is that I am creating an extension that inspects and runs code in the current workspace.

I can open up one or more PRs for this if that would be helpful.

Nicholas-Schaub avatar Dec 21 '21 18:12 Nicholas-Schaub

Python is installed in C:\Users\x\AppData\Local\Programs\Python\Python311\python.exe, but it checked at C:\Python310\python.exe

take path from which python or where python command

SmartManoj avatar Dec 19 '23 03:12 SmartManoj