Cannot get gcloud to work with Python and Pycharm
<p>I am trying to connect to the Google App Engine Datastore from my local machine. I have spent all day digging in to this without any luck.</p>

<p>I have tried the approach here (as well as alot of other suggestions from SO such as <a href="http://stackoverflow.com/questions/27057935/using-gcloud-python-in-gae">Using gcloud-python in GAE</a> and <a href="http://stackoverflow.com/questions/34584937/unable-to-run-dev-appserver-py-with-gcloud">Unable to run dev_appserver.py with gcloud</a>):</p>

<p><a href="http://stackoverflow.com/questions/34572330/how-to-access-a-remote-datastore-when-running-dev-appserver-py/34575005#34575005">How to access a remote datastore when running dev_appserver.py?</a></p>

<p>I first installed gcloud based on this description from google:
<a href="https://cloud.google.com/appengine/docs/python/tools/using-libraries-python-27" rel="nofollow">https://cloud.google.com/appengine/docs/python/tools/using-libraries-python-27</a> </p>

<p>According to the description I should add the following to my appengine_config.py:</p>

<pre><code>from google.appengine.ext import vendor
vendor.add('lib')
</code></pre>

<p>If I do that I get an error saying <code>ImportError: No module named gcloud</code></p>

<p>If I then move the code to my main.py it seems to pickup the lib-folder and the modules there. That seems a bit strange to me, since I thought appengine_config was being run first to make sure things were initialised.
But now I am getting the following stack trace:</p>

<pre><code>ERROR    2016-09-23 17:22:30,623 cgi.py:122] Traceback (most recent call last):
  File "/Users/thomasd/Documents/github/myapp/main.py", line 10, in &lt;module&gt;
    from gcloud import datastore
  File "/Users/thomasd/Documents/github/myapp/lib/gcloud/__init__.py", line 17, in &lt;module&gt;
    from pkg_resources import get_distribution
  File "/Users/thomasd/Documents/github/myapp/lib/pkg_resources/__init__.py", line 2985, in &lt;module&gt;
    @_call_aside
  File "/Users/thomasd/Documents/github/myapp/lib/pkg_resources/__init__.py", line 2971, in _call_aside
    f(*args, **kwargs)
  File "/Users/thomasd/Documents/github/myapp/lib/pkg_resources/__init__.py", line 3013, in _initialize_master_working_set
    dist.activate(replace=False)
  File "/Users/thomasd/Documents/github/myapp/lib/pkg_resources/__init__.py", line 2544, in activate
    declare_namespace(pkg)
  File "/Users/thomasd/Documents/github/myapp/lib/pkg_resources/__init__.py", line 2118, in declare_namespace
    _handle_ns(packageName, path_item)
  File "/Users/thomasd/Documents/github/myapp/lib/pkg_resources/__init__.py", line 2057, in _handle_ns
    loader.load_module(packageName)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pkgutil.py", line 246, in load_module
    mod = imp.load_module(fullname, self.file, self.filename, self.etc)
  File "/Library/Python/2.7/site-packages/google/cloud/logging/__init__.py", line 18, in &lt;module&gt;
  File "/usr/local/google_appengine/google/appengine/tools/devappserver2/python/sandbox.py", line 999, in load_module
    raise ImportError('No module named %s' % fullname)
ImportError: No module named google.cloud.logging.client
</code></pre>

<p>What am I doing wrong here?</p>

<p>I solved it this way:- </p>

<p>1.) Create a lib folder in your project path.</p>

<p>2.) Install gcloud libraries by running following command into terminal from your project path:-</p>

<pre><code>    pip install -t lib gcloud
</code></pre>

<p>3.) Create an appengine_config.py module in your project and add following lines of code:-</p>

<pre><code>    import sys
    import os.path
    sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'lib'))
</code></pre>

<p>4.) After this, you can import like this:-</p>

<pre><code>    from gcloud import datastore
</code></pre>

<p>5.) To save data into live google datastore from local:-</p>

<pre><code>    client = datastore.Client("project-id")
    key = client.key('Person')
    entity = datastore.Entity(key=key)
    entity['name'] = ashish
    entity['age'] = 23
    client.put(entity)
</code></pre>

<p>It will save an entity named Person having properties name and age. Do not forget to specify your correct project id.</p>

python google-app-engine gcloud-python google-cloud-python