0

Is there a way to import 3rd party libraries to GAE in a way that is not manual?

i.e. not the solution mentioned here:
How to include third party Python libraries in Google App Engine?

The ideal would be to pip install -r requirements.txt into a virtualenv, then somehow make that library available in the local GAE development server, and of course on GAE itself.

Community
  • 1
  • 1
Ben
  • 5,085
  • 9
  • 39
  • 58
  • have you tried this? http://blog.altlimit.com/2013/06/google-app-engine-virtualenv-tool-that.html I created this for this exact purpose. It should work with virtualenv, just run the bin/gaenv from the virtualenv that you are using to create the symlinks found on requirements.txt – Faisal Mar 07 '14 at 04:50

1 Answers1

1

If you are already using pip and virtualenv, you need to create symlinks from ./lib/python2.7/site-packages/"libxxx" to your GAE project directory (where . is the root of your virtualenv directory, and libxxx is the name of the 3rd party library you're willing to install).

If there are symbolic links in your GAE project, then appcfg.py will resolve these links when publishing your app on Google's infrastructure.

For example, on Mac OS X, to install HTTPlib on GAE, I did the following:

ln -s ~/Projets/myproject/lib/python2.7/site-packages/httplib2/ ~/Projets/myproject/src/packages/libs/httplib2/

After that, provided your code is somewhere inside ~/Projets/myproject/src, you can use the library using: from packages.libs import httplib2.

Romain
  • 3,718
  • 3
  • 32
  • 48
  • would that mean that you'd need to `pip install -d ~/myproject `? Because when I use the regular `pip install -r requirements.txt` inside of an virtualenv, it doesn't install into `~/myproject/lib/python2.7/site-packages/`. – Ben Mar 05 '14 at 01:09
  • No, do not change your `pip install` directory, it would break your existing setup. The initial packages location is not really relevant. Wherever your virtualenv is located, you need to symlink the packages from `/path/to/your/venv/lib/python2.7/site-packages/"libxxx"` to a subdirectory of your GAE project (it doesn't even need to be `/src/packages/libs` like in my answer, it's just a common way of organizing GAE projects). – Romain Mar 05 '14 at 09:45
  • In fact your virtualenv does not need to share a common root directory with your GAE project, but I like keeping them at the same location, in case I want to build another project with other Python libs. – Romain Mar 05 '14 at 09:45