When I wrote Python in VSCode, I got an import-error even though it was in the pip library, so I fixed it.
Create a Python virtual environment with virtualenvwrapper With pip in the virtual environment introduced in I have installed "google-cloud-datastore", but it is not recognized correctly by VS Code.
Launch the VS Code terminal
$ workon [Corresponding virtual environment name]
Even if I switch to the environment with the library as, the part of "from .. import ..." remains a red wavy line.
Open "settings.json" from the screen below and go to edit.
File -> Preferences -> Settings
Or
「 ctrl + , 」
Open the settings with and open "Edit in settings.json" in the "Python> Auto Complete: Extra Paths" column.
First, log in to the virtual environment that contains the library with pip and find out the location of the python interpreter.
$ workon [Virtual environment name]
$ which python
Save the python interpreter path you wrote down by adding the following elements (ctrl + s).
{
"workbench.startupEditor": "newUntitledFile",
"git.autofetch": true,
"emmet.extensionsPath": "",
"emmet.variables": {
"lang": "ja",
"charset": "UTF-8"
},
"editor.snippetSuggestions": "top",
"editor.tabSize": 2,
"go.useLanguageServer": true,
"python.autoComplete.extraPaths": [
],
"python.pythonPath": "/home/[ubuntu username]/.virtualenvs/[Virtual environment name]/bin/python"
}
I was able to resolve it safely!
I use VSCode because it's easy to see and use, but I'm glad I was able to eliminate the incorrect grammar error display.
Future development is likely to progress.
This time it's over.
Reference: Linting | Python in Visual Studio Code
Recommended Posts