[VSCode] unable to import'google.cloud' What to do when pylint (import-error) does not recognize the Python import statement

When I wrote Python in VSCode, I got an import-error even though it was in the pip library, so I fixed it.

environment

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

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.

vscode-setting.png

Added to settings.json

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!

Finally

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

[VSCode] unable to import'google.cloud' What to do when pylint (import-error) does not recognize the Python import statement
Example of what to do when the sample script does not work (OpenCV-Python)
What to do when the graph does not appear in jupyter (ipython) notebook
What to do when "cannot import name xxx" [Python]
What to do when python3 type venv does not work well on Raspberry Pi
What to do when Python starts up in Anaconda does not come out unexpectedly
What to do if Python does not switch from the System version in pyenv
What to do if you get the error "Error: opencv3: Does not support building both Python 2 and 3 wrappers" when installing openCV 3
What to do when the jupyterlab extension settings are not reflected
What to do when the value type is ambiguous in Python?
Notes on what to do when matplotlib scatter () / scatter3d () does not work
[Mac OS] What to do when Python is not installed as a framework. Is displayed when import matplotlib is performed.
[EC2] What to do when selenium is stuck and processing does not proceed
[Python] Type Error:'WebElement' object is not iterable What to do when an error occurs
What to do when is not in the sudoers file.This incident will be reported.
Solution when Linux does not recognize the built-in camera
What to do if the progress bar is not displayed in tqdm of python
What to do if sys / cdefs.h does not exist
What to do when you can't bind CaboCha to Python
What to do when Japanese is not displayed on matplotlib
What to do when an error occurs with import _ssl
What to do when "SSL: CERTIFICATE_VERIFY_FAILED _ssl.c: 1056" appears in Python
Check when the Docker container does not connect to the Internet
ImportError: No module What to do when you are told
[Beginner] What to do when "[Errno 2] File b'test.csv' does not exist: b'test.csv" is displayed when reading pandas csv
NameError: global name'dot_parser' is not defined and what to do when it comes up in python
What to do if the user name is changed and the pyenv library path does not pass
[AWS] What to do when the ping command causes a "timeout"
[Beanstalk] What to do when an error occurs with import uuid
What to do if python says "fatal error:'stdio.h' file not found"
What to do if Insecure Platform Warning appears when running Python
What to do when you get "I can't see the site !!!!"
What to do when ModuleNotFoundError: No module named'XXX' occurs in Python
What to do if you get "The session could not be opened" when installing CentOS on VirtualBox
What to do when Ubuntu crashes
What to do if you get a "Wrong Python Platform" warning when using Python with the NetBeans IDE
[Python] What to do when PEP8 is violated in the process of importing from the directory added to sys.path
[Python] How to import the library
What to do with PYTHON release?
What to do when "OS Error: [WinError 126] The specified module cannot be found" appears in import torch
What to do when you get angry that libxml / xmlversion.h does not exist when you put lxml with pip
What to do if you get the error RuntimeError: Python is not installed as a framework when trying to use matplitlib and pylab in Python 3.3
What skills do I need to program with the FBX SDK Python?
What to do when the result downloaded via scrapy is in English
[Docker] What to do when error Couldn't find the binary git appears
What to do if pyenv install does not proceed with an error
[Python] What to do when an error related to SSL authentication is returned
What to do if the server doesn't start with python manage.py runserver
What to do if an error occurs when importing numpy with VScode
Check items when the imported python module does not work as expected
Processing when the key input of Python pygame does not go well.
What to do when the warning "The environment is in consistent ..." appears in the Anaconda environment
[Introduction to Python] What is the method of repeating with the continue statement?
[VScode] autopep8 format does not work [Python]
Python> Python does not include the last offset
I managed to solve the situation where Python does not work on Mac
[python] What to do when an error occurs in send_keys of headless chrome
What to do when "TypeError: must be string, not int…" appears when using strptime
What to do when SSL error occurs in pip in Windows10, miniconda, VScode environment
What to do when a warning appears around Python integration in Neovim's CheckHealth
When using PyQtGraph with Python Pyside, pay attention to the order of import