vscode.py
vscode.py copied to clipboard
Python was not found
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
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.
Will fix this soon 👍
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.
I think I actually figured out how to resolve this. It comes with only a few minor code changes. It basically works like this:
-
Get the path the current active environment path from the
vscode-python
extension api https://github.com/microsoft/vscode-python -
When running
extension.py
, replacepython3
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.
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