0

I am unable to get a Python package, gspread, to work in GAE.

My project is in D:\Documents\Google Cloud\myapp. I installed gspread using:

c:\python27\python.exe setup.py install --home="D:\Documents\Google Cloud\myapp"

All the files appear to be installed in D:\Documents\Google Cloud\myapp\lib\python without offering me a choice. In fact, I have to add this path to PYTHONPATH in order for setup.py to run properly.

If I then run Python, I can import gspread in the interpreter.

However, in myapp, I can't import (ImportError: No module named gspread) even when I added that long path to sys.path. My sys.path at run-time contains, among other values,:

'D:\\Documents\\Google Cloud\\myapp\\lib\\python'
'D:\\Documents\\Google Cloud\\myapp'
'D:\\Documents\\Google Cloud\\myapp\\lib'

What is needed to get this third party module to work?

Old Geezer
  • 14,854
  • 31
  • 111
  • 198
  • 1
    Possible duplicate of [How to include third party Python libraries in Google App Engine?](http://stackoverflow.com/questions/14850853/how-to-include-third-party-python-libraries-in-google-app-engine) – Tim Hoffman Jan 21 '16 at 10:41
  • Yes, I did see that, but couldn't find anything that's applicable. My module is not in source form but added via setup.py. I have no time to go into the details of how setup.py works. – Old Geezer Jan 21 '16 at 10:55
  • It's all applicable. I know how setup.py works. re-read the answer it is right there for you `import sys sys.path.insert(0, 'libs')` . Notice the similiarity between hello/libs in the answer and your structure. You need to realize the dev server is emulating the production sandbox and won't user fully qualified paths. – Tim Hoffman Jan 21 '16 at 14:13
  • The on thing I wouldn't do is include the path in the top of your app. Use app_config.py to set things up like global paths as this is loaded before any of your code. – Tim Hoffman Jan 21 '16 at 14:14
  • Sorry, forgot to mention the above is still running on my local machine, not deployed to Google yet. I did sys.path.insert, and other than the first path in `sys.path` which I added manually, the others are all included by the GAE Launcher. In the `...lib\path` folder, there is a `gspread-0.2.5-py2.7.egg` file among others. Is `...lib\python` the correct value that must in `sys.path` for `gspread` to be located? – Old Geezer Jan 21 '16 at 15:03

1 Answers1

0

I got it to work by adding the following, path of a file and not a folder, to sys.path:

D:\Documents\Google Cloud\Drive-1185\lib\python\gspread-0.2.5-py2.7.egg

A relative path may be used as the working directory is the app directory. To deploy to Google's servers, obviously only a relative path can be used, and not only that, backward slashes must be replaced with forward slashes.

Old Geezer
  • 14,854
  • 31
  • 111
  • 198