No module named cloudstorage

I am trying to add Google Cloud Storage functionality to a GAE app that is already running with significant functionality. I work entirely within PyCharm on my development computer, which is a Mac running the latest OS X.

My Python module contains this statement:
     import cloudstorage as gcs
as shown in the sample code at https://cloud.google.com/appengine/docs/python/googlecloudstorageclient/getstarted

When I first added that line to a module I'm developing within my app, PyCharm said "Module cloudstorage not found" (or something like that) in the editor.

I then followed both the "pip" and the "svn" instructions at https://cloud.google.com/appengine/docs/python/googlecloudstorageclient/download
to download the GCS Client Library.

I actually used "pip" three times:
  • Once without the "-t" option
  • Once using the "-t" option to specify my application directory's "lib" subdirectory
  • Once using:
pip install GoogleAppEngineCloudStorageClient -t /Applications/GoogleAppEngineLauncher.app//Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib

As mentioned, I also executed the "svn" command. Then, as mentioned in http://stackoverflow.com/questions/25100031/install-python-google-cloud-storage-client-on-ubuntu-14-04, I ran "cd gcs-client/src" and "sudo python setup.py install".

After each of those successful but different installations of the GCS Client Library, I looked at the PyCharm editor window for my module, and it always had the same error. But as an experiment, I would also try restarting PyCharm, and also try running my app.

At some point, the editor window stopped showing the error. It was not immediately after one of those steps above, but after going away to read various webpages and then coming back to see if somehow the error had gone away. I don't know which of the installations was the one that got rid of the error message in the PyCharm editor.

In any case, whenever I try to run the app (again, inside PyCharm), I always get the error "ImportError: No module named cloudstorage" on the import statement.

The Run/Debug Configuration page for this app has both "Add content roots to PYTHONPATH" and "Add source roots to PYTHONPATH" checked. (By the way, I've read the docs and I still don't understand the difference between those two. Just FYI for your tech writer.)

Of course the main help I want is how to get past the "No module named cloudstorage" runtime error, even though the import statement no longer shows an error.

I think I also have as many as three spurious versions of the GCS Client Library. It's not really your problem, but if you have any idea how I can delete the spurious versions so that they're not just lying around, I'd be most grateful for that help as well.

SUMMARY

Though I have given detailed references, I think my question may actually be more general: How is the PyCharm editor able to know where an import library is, but when I run the app, I get "No module named ..." on that same import statement? But maybe it's not a general problem, maybe it's something specific to GAE or GCS. Whatever the issue, thanks for any help you can give.
1 comment
Comment actions Permalink
I found the solution to my show-stopper problem with import.

Since the "cloudstorage" directory is under <app>/lib, the import statement needs to say:

  import lib.cloudstorage

or, in my case,

  import lib.cloudstorage as gcs
0

Please sign in to leave a comment.