3

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?

Fariborz Ghavamian
  • 809
  • 2
  • 11
  • 23
  • Possible duplicate of [import cloudstorage, SyntaxError: invalid syntax](https://stackoverflow.com/questions/48560171/import-cloudstorage-syntaxerror-invalid-syntax) – dsesto Feb 01 '18 at 14:44
  • did you find a solution? – Manza Aug 18 '18 at 02:21

3 Answers3

5

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

Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
1

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.

tourfl
  • 11
  • 2
0

Looks like gcloud is not installed on your system.

pip install --upgrade gcloud

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

Community
  • 1
  • 1
Alexander Ejbekov
  • 5,594
  • 1
  • 26
  • 26
  • 1
    Both `gcloud` and `google-api-python-client` are installed. I still get the same error. – Fariborz Ghavamian Feb 01 '18 at 14:50
  • Within the same installation? That is, you are executing `python -c "import cloudstorage"` while pip might be a pip3 installation and installing in python3. – Alexander Ejbekov Feb 01 '18 at 14:52
  • The installations are in a virtualenv called `ve_python2 `. `python --version Python 2.7.14` and `pip --version pip 9.0.1 from ve_python2/lib/python2.7/site-packages (python 2.7)`. There are no other pythons in `ve_python2/lib`. – Fariborz Ghavamian Feb 01 '18 at 14:59