skaul05
skaul05

Reputation: 2344

Google Cloud Client Libraries in Python 2.7

I have been using Google Cloud Client Libraries for my project and getting import errors.

Import Error: No module named cloud

I have app.yaml in my project which looks like the following:

runtime: python27

api_version: 1
threadsafe: no

handlers:
- url: /.*
  script: main

Now I have configured requirements.txt which has google-cloud-datastore and google-cloud-storage

requirements.txt

Flask==1.0.2
google-cloud-datastore
google-cloud-storage
google-api-python-client

Now when I import google.cloud in my main.py file I get the import error.

from google.cloud import storage

I have deployed the project on Google App Engine

After getting errors I changed my Project to Python 3.7 and then deployed on App Engine and to my surprise, it worked perfectly.

So is it because google-api-python-client is deprecated in Python 2.7 or am I doing something wrong in here

Upvotes: 1

Views: 805

Answers (1)

ASSILI Taher
ASSILI Taher

Reputation: 1349

Please note that google-cloud-storage doesn't support App Engine Standard environment for Python 2.7. Fortunately, Google Cloud provide an alternative for Python 2.7. So, to use Google cloud storage, you need to install GoogleAppEngineCloudStorageClient.

In lib's parent directory, use this command:

pip install -t lib GoogleAppEngineCloudStorageClient

Then, you can import cloudstorage like this:

import cloudstorage

Please find the official documentation: The example was elaborate with webapp2 but it works with Flask.

Upvotes: 2

Related Questions