简体   繁体   中英

import cloudstorage, ImportError: No module named google.appengine.api

I would like to use Google Cloud Storage Client Library Functions .

For that I have to import the cloudstorag . To get the cloudstorage I download Google Cloud Storage client library .

I try to import cloudstorage using python -c "import cloudstorage" . I get the following error:

Traceback (most recent call last):
File "<string>", line 1, in <module>
  File "cloudstorage/__init__.py", line 20, in <module>
    from .api_utils import RetryParams
  File "cloudstorage/api_utils.py", line 45, in <module>
    from google.appengine.api import app_identity
ImportError: No module named google.appengine.api

Am I missing something?

When you execute python -c "import cloudstorage" you're attempting to run a standalone application. But the GCS library you're trying to use is for a (standard environment) GAE application, which cannot be executed as a standalone app, it needs to run in a GAE sandbox (locally that's dev_appserver.py ). See GAE: AssertionError: No api proxy found for service "datastore_v3" .

And the library needs to be installed inside your GAE app, see Copying a third-party library .

If you're not developing a standard env GAE app and indeed you want to write a standalone one, you're not looking at the right documentation. You need to use a different library than the GAE-specific one(s). See Cloud Storage Client Libraries

Looks like gcloud is not installed on your system.

pip install --upgrade gcloud

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

You can add this lines, which will add the path of the sdk tools:

import pkgutil
import google

google.__path__ = pkgutil.extend_path(google.__path__, google.__name__)

For unittesting, it could be useful to run in standalone mode.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM