pythonvisual-studio-codegoogle-oauthgoogle-api-python-client

Import "google.oauth2.credentials" could not be resolved Visual Studio Code


I am trying to use google.oauth2, google_auth_oauthlib.flow and googleapiclient.discovery for my web app. But I'm getting these errors:

Import "google.auth.transport.requests" could not be resolved
Import "google.oauth2.credentials" could not be resolved
Import "googleapiclient.discovery" could not be resolved

And output is : from google.auth.transport.requests import Request ModuleNotFoundError: No module named 'google' Here's my pip list :

    google                   3.0.0
    google-api-core          2.8.2
    google-api-python-client 2.51.0
    google-auth              2.8.0
    google-auth-httplib2     0.1.0
    google-auth-oauthlib     0.5.2
    googleapis-common-protos 1.56.3
    gspread                  5.4.0
    httplib2                 0.20.4
    oauth2client             4.1.3
    oauthlib                 3.2.0
    requests                 2.28.0
    requests-oauthlib        1.3.1

Why am I getting these errors and how to resolve them?


Solution

  • Maybe there is more than one python environment on your machine, please use CTRL + SHIFT + P to open the command palette type and select Python: Select Interpreter (or click on the interpreter version displayed in the lower right corner).

    enter image description here

    Choose the correct python interpreter and this will solve your problem.