packapotatoes
packapotatoes

Reputation: 33

"ImportError: No module named pkg_resources" when importing google.cloud.datastore

I am attempting to use the Google Cloud Datastore, but importing google.cloud.datastore gives an ImportError:

ERROR    2018-03-13 19:28:29,013 wsgi.py:263] 
Traceback (most recent call last):
  File "/home/<user>/Software/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/home/<user>/Software/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "/home/<user>/Software/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject
    obj = __import__(path[0])
  File "/home/<user>/Projects/<my_project>/main.py", line 1, in <module>
    from my_project import app
  File "/home/<user>/Projects/<my_project>/<my_project>/__init__.py", line 2, in <module>
    from my_project.submit.controllers import submit
  File "/home/<user>/Projects/<my_project>/<my_project>/submit/controllers.py", line 6, in <module>
    from . import model_datastore
  File "/home/<user>/Projects/<my_project>/<my_project>/submit/model_datastore.py", line 2, in <module>
    from google.cloud import datastore
  File "/home/<user>/Projects/<my_project>/env/local/lib/python2.7/site-packages/google/cloud/datastore/__init__.py", line 57, in <module>
    from pkg_resources import get_distribution
ImportError: No module named pkg_resources

I am on Linux Mint attempting to run a Google App Engine local dev server.

I am using a virtual environment. Both setuptools and pkg_resources are installed and updated in the virtual environment. When I enter the python cmd line interpreter from the virtual env and import pkg_resources, it works fine. When I run the google app engine dev server by doing dev_appserver app.yaml, everything works fine until I access the page that activates the handler that imports datastore, then I get this error.

None of the other similar posts about 'pkg_resources` import error were helpful.

If there is any other info I can provide that would help, please let me know. Thanks!

Upvotes: 2

Views: 2013

Answers (1)

Dan Cornilescu
Dan Cornilescu

Reputation: 39814

In the standard environment you need to install all your dependencies inside your application. See Using third-party libraries.

Whatever you have installed in the local environment (virtual or not) doesn't matter, GAE doesn't know how to use those and your app might not work properly locally and definitely won't work when deployed on GAE.

You traceback indicates that you're loading the datastore library from your virtual env, not from your app, which is most likely why it doesn't work:

.../env/local/lib/python2.7/site-packages/google/cloud/datastore/__init__.py

You need to fix your app dependency installation.

This discussion might be of interest as well: No module named warnings when starting GAE inside virtualenv locally

Upvotes: 1

Related Questions