Reputation: 221
I started using venvs on Visual Studio Code, and when I am trying to use pandas, by import pandas
it gives me this error
"Import "pandas" could not be resolved from source"
So I tried to use ctrl+shift+p
to change python interpreter in vscode, I get this error
"Command Python resulted in an error (comand 'python.setInterpreter' not found).
Upvotes: 22
Views: 51904
Reputation: 23
I had some issues with the same error - it turned out that the MS Python extension was set by default to a pre-release version (v2024.21.2024112701); I switched to the Release Version using the available button.
After this the Python file association re-established itself and my conda environments were recognised.
PS Also downgrade the python debugger to avoid being prompted for a debugger when running code with CTRL + F5.
Upvotes: 0
Reputation: 773
In my case, none of the above described solutions worked.
I updated the VS code and reloaded the window and that resolved the issue.
Current VS code version is 1.85.2
.
Upvotes: 0
Reputation: 83676
In my case this happened when usig Remote SSH extension and doing Python development on a remote server. The issue was caused by Datadog agent that corrupted any application on the server.
Upvotes: 0
Reputation: 35
I was able to fix this issue by adding below details in settings.json of vscode.
"python.venvFolders" : <Your venv folders>
"python.venvPath" : <Your Python path>
Upvotes: 1
Reputation: 589
For me, shifting from restricted mode to trusted window mode worked.
Just click on the restricted window on the bottom and just select "Trust" in the pop up window.
https://code.visualstudio.com/docs/editor/workspace-trust#_extensions
Upvotes: 52
Reputation: 781
In my case, i just reinstall the python extension from microsoft then reload the vscode.
Upvotes: 3
Reputation: 955
In my case, I solve it by clicking the "Extensions" button in the left sidebar of VSCode and "Reload" python. (which will show a blue reload button in the lower left corner of Python's block, just click it)
It works for me!!
Upvotes: 5
Reputation: 153
I suggest 2 ways to fix this, first uninstalling and reinstalling the extensions. On Linux (and MacOS I believe), deleting ~/.vscode/extensions/
and then manually reinstalling will help. If that does not work you can try manually setting the python interpreter (see: vscode documentation on manually specifying an interpreter).
For more information, I recommend you to look through How to start debugging Python 3.6 in Visual Studio Code?
Upvotes: 2