Python install apiclient discovery

ImportError: No module named apiclient.discovery

You should be able to get these dependencies with this simple install:

sudo pip install --upgrade google-api-python-client 

This is described on the quick start page for python.

apiclient was the original name of the library.
At some point, it was switched over to be googleapiclient .

If your code is running on Google App Engine, both should work.

If you are running the application yourself, with the google-api-python-client installed, both should work as well.

Although, if we take a look at the source code of the apiclient package’s __init__.py module, we can see that the apiclient module was simply kept around for backwards-compatibility.

Retain apiclient as an alias for googleapiclient.

So, you really should be using googleapiclient in your code, since the apiclient alias was just maintained as to not break legacy code.

# bad from apiclient.discovery import build # good from googleapiclient.discovery import build 

apiclient is not in the list of third party library supplied by the appengine runtime: http://developers.google.com/appengine/docs/python/tools/libraries27 .

You need to copy apiclient into your project directory & you need to copy these uritemplate & httplib2 too.

Note: Any third party library that are not supplied in the documentation list must copy to your appengine project directory

Источник

Utilizing Python’s googleapiclient discovery module

The error «ImportError: No module named apiclient.discovery» occurred while using Python 3.6.5. However, we found a solution that worked in our case. Another solution is to use a unit test, as demonstrated below, which provides test results and a coverage report.

How to mock googleapiclient.discovery.build

Your mocking of the googleapiclient.discovery.build method was incorrect. Refer to the provided unit test solution for assistance.

import googleapiclient.discovery import logging class Service: def __init__(self, project, event): self.project_id = project self.compute = googleapiclient.discovery.build('compute', 'v1', cache_discovery=False) self.event = event self.zones = self._validate_event() def _validate_event(self): if "jsonPayload" not in self.event: zones = self.compute.zones().list(project=self.project_id).execute()['items'] else: zones = self.compute.zones().get(project=self.project_id, zone=self.event["jsonPayload"]["resource"]["zone"]).execute() logging.debug(f"Identified Zones are ") return [zone["name"] for zone in zones] 
from unittest import TestCase, main from unittest.mock import patch import code class TestService(TestCase): def setUp(self): self.project_id = "sample-project-id" @patch('code.googleapiclient.discovery') def test__validate_event_with_empty_inputs(self, mock_discovery): # Arrange mock_discovery.build.return_value.zones.return_value.list.return_value.execute.return_value = < "items": []> # Act obj = code.Service(event=<>, project=self.project_id) # Assert mock_discovery.build.assert_called_once_with('compute', 'v1', cache_discovery=False) mock_discovery.build.return_value.zones.assert_called_once() mock_discovery.build.return_value.zones.return_value.list.assert_called_once_with(project='sample-project-id') mock_discovery.build.return_value.zones.return_value.list.return_value.execute.assert_called_once() self.assertEqual(obj.zones, ["eu-west-1"]) if __name__ == '__main__': main() 

Test outcome along with the coverage report of the unit.

. ---------------------------------------------------------------------- Ran 1 test in 0.002s OK Name Stmts Miss Cover Missing ----------------------------------------------------------------------- src/stackoverflow/56794377/code.py 14 1 93% 16 src/stackoverflow/56794377/test_code.py 16 0 100% ----------------------------------------------------------------------- TOTAL 30 1 97% 

Python — How to pip install Google-API-Client in Virtual, Try using either. pip3 install google-client-api. or. python3 -m pip install google-client-api. The first command should work in most systems, the second should work in pretty much any system with Python3. Share. Improve this answer. answered Nov 18, 2021 at 1:16. import huh.

Python install module apiclient

sudo pip install --upgrade google-api-python-client 

Ensure that only google-api-python-client is installed and not apiclient to avoid any collision. Execute the given command to verify.

pip install --force-reinstall google-api-python-client 

I encountered a difficulty that was hard to solve. Eventually, I found a solution that worked.

pip install google-api-python-client==1.5.3

Prior to this, my system had version 1.6.2 installed. It appears that newer releases of google-api-python-client have abandoned the use of apiclient and opted for the googleapiclient alternative. However, this has created a problem as certain packages (such as airflow) still rely on the original apiclient.discovery import statement.

In case you have python3 already installed, and you plan to install apiclient, it might end up getting installed in the python3 directory. I had encountered a similar issue, but my program ran without any trouble once I removed the python3 installation.

Unable to use API key with GCP’s python discovery client, from googleapiclient import discovery storage_service = discovery.build(‘storage’, ‘v1′, developerKey=»AIzaSyhidingKeyVm60c») storage_service.buckets().list(project=’my-project’).execute() python google-cloud-platform client google-api-python-client. Share. Follow asked Mar 14 at 13:13. …

ImportError: No module named googleapiclient.discovery

The issue of «ImportError: No module named apiclient.discovery» has been addressed in a separate thread.

Also this one worked in our case

pip install —upgrade google-api-python-client

Having encountered a similar problem, I resorted to using the requirements.txt file to install the requisite libraries. However, despite including google-api-python-client==1.6.2 in the file, the pip install was unsuccessful in installing the library. To remedy this, I removed the version number from the requirements.txt file, leaving only google-api-python-client. Subsequently, I ran the pip install command again, and this resolved the issue, allowing the appengine app to function properly.

I faced difficulty in deploying my app on Heroku, despite it working fine locally. The issue was with the requirements.txt file, which had both google-api-python-client==1.6.2 and oauth2client==4.0.0 versions. I was able to resolve the issue by deleting the app and redeploying after removing the version data of google-api-python-client and deleting oauth2client==4.0.0. Another option would be to manually uninstall google-api-python-client and all its dependencies, and then reinstall them.

How to use google cloud speech api in python, Install pip (am sure you already have this) and virtualenv . execute following commands: $ virtualenv env $ source env/bin/activate Then install from requirements.txt pip install -r requirements.txt define and export google credentials path (you are already doing this). export …

Python googleapiclient of `kubectl get deployments`?

from google.oauth2 import service_account from google.cloud.container_v1 import ClusterManagerClient from kubernetes import client import google.auth.transport.requests project_id = "my-project" zone = "my-zone" cluster_id = "my-cluster" credentials = service_account.Credentials.from_service_account_file( 'key.json') # Get GKE cluster details for the given cluster. cluster_manager_client = ClusterManagerClient(credentials=credentials) cluster = cluster_manager_client.get_cluster( project_id=project_id, zone=zone, cluster_id=cluster_id) # Get a token with the scopes required by GKE kubeconfig_creds = credentials.with_scopes( ['https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/userinfo.email']) auth_req = google.auth.transport.requests.Request() kubeconfig_creds.refresh(auth_req) #Client below is the k8s-client. configuration = client.Configuration() # the enpoint is an ip address, so we can't use the SSL verification :( configuration.host = "https://"+cluster.endpoint+":443" configuration.verify_ssl = False kubeconfig_creds.apply(configuration.api_key) client.Configuration.set_default(configuration) #Use any kubernetes client methods, here I get all the deployments deployments = client.AppsV1Api().list_deployment_for_all_namespaces() for d in deployments.items: . 

Python — Annotating image file to text using, # Wrong API being used service = googleapiclient.discovery.build(‘language’, ‘v1’); # Correct API being used service = googleapiclient.discovery.build(‘vision’, ‘v1’); In this Google API Client Libraries page you will find the whole list of available APIs and their names and versions available.

Источник

Читайте также:  Create Record
Оцените статью