I'm using pylance to check my Python code. It tells me
Import "astor" could not be resolved
When I switch to the terminal within VS Code:
I'm pretty certain that the issue is that it uses another environment. I'm using pyenv by default and I would like if vscode would use the same environment. But at the very least I need to be able to access the environment it is using to install packages.
Interestingly, the status bar seems to show something else, because in that environment I have astor installed:
Select and activate an environment# To select a specific environment, use the Python: Select Interpreter command from the Command Palette (Ctrl+Shift+P). Note: If the Python extension doesn't find an interpreter, it issues a warning.
Pylance is an extension for Visual Studio Code (VSCode) to help the editor understand Python code. It simply means that Pylance is not using the same Python binary as your project. Open the command palette and type "Python: select interpreter", then find your Python interpreter that has pyodbc installed.
I found this link that informs us that we should add an extra path.
These extra roots must be specified to the language server. The easiest way to do this (with the VS Code Python extension) is to create a workspace configuration which sets python.analysis.extraPaths. For example, if a project uses a sources directory, then create a file .vscode / settings.json in the workspace with the contents:
{
"python.analysis.extraPaths": ["./sources"]
}
https://github.com/microsoft/pylance-release/blob/master/TROUBLESHOOTING.md#unresolved-import-warnings
Another easy way to solve this on VSCODE:
ctrl
+ ','Also if you have problems importing local files, you can do the same thing and add your working directory path to solve the problem :) just add 'C: your working directory goes here' in addition to './sources' in the same way ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With