Adding libraries to django nonrel
Question: I've a project in Django which I'm trying to port to Django-nonrel so that I
can upload it to Google app Engine. I've installed django-nonrel and other
required libraries by going through the
<http://djangoappengine.readthedocs.org/en/latest/installation.html>

namely: django-nonrel djangoappengine djangotoolbox django-autoload django-
dbindexer

that is by downloading their zip files and placing them in my app directory.
So, my app directory is: >

    
    
    <app>/autoload
    <app>/dbindexer
    <app>/django
    <app>/djangoappengine
    <app>/djangotoolbox
    

I also have django in my project directory and have started the project by:

    
    
    PYTHONPATH=. python django/bin/django-admin.py startproject \
       --name=app.yaml --template=djangoappengine/conf/project_template app
    

If I am adding an external library with pip and adding it to the
**INSTALLED_APPS** of my app's **settings.py** , it is not recognised by my
django-nonrel which is pretty obvious considering the fact that django-nonrel
is not installed on my system. It gives me the following error

    
    
    Traceback (most recent call last):
      File "/usr/local/google_appengine/google/appengine/tools/devappserver2/module.py", line 1390, in _warmup
        request_type=instance.READY_REQUEST)
      File "/usr/local/google_appengine/google/appengine/tools/devappserver2/module.py", line 884, in _handle_request
        environ, wrapped_start_response)
      File "/usr/local/google_appengine/google/appengine/tools/devappserver2/request_rewriter.py", line 314, in _rewriter_middleware
        response_body = iter(application(environ, wrapped_start_response))
      File "/usr/local/google_appengine/google/appengine/tools/devappserver2/module.py", line 1297, in _handle_script_request
        request_type)
      File "/usr/local/google_appengine/google/appengine/tools/devappserver2/module.py", line 1262, in _handle_instance_request
        request_type)
      File "/usr/local/google_appengine/google/appengine/tools/devappserver2/instance.py", line 371, in handle
        raise CannotAcceptRequests('Instance has been quit')
    CannotAcceptRequests: Instance has been quit
    (nonrel)apurva@apurva-HP-ProBook-6470b:~/project/flogin$ python manage.py runserver
    INFO     2015-08-11 16:06:54,606 sdk_update_checker.py:229] Checking for updates to the SDK.
    INFO     2015-08-11 16:06:55,511 sdk_update_checker.py:257] The SDK is up to date.
    INFO     2015-08-11 16:06:55,633 api_server.py:205] Starting API server at: http://localhost:60055
    INFO     2015-08-11 16:06:55,847 dispatcher.py:197] Starting module "default" running at: http://127.0.0.1:8080
    INFO     2015-08-11 16:06:55,847 admin_server.py:118] Starting admin server at: http://localhost:8000
    INFO     2015-08-11 16:06:58,966 __init__.py:52] Validating models...
    ERROR    2015-08-11 16:06:59,045 wsgi.py:263] 
    Traceback (most recent call last):
      File "/usr/local/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
        handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
      File "/usr/local/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
        handler, path, err = LoadObject(self._handler)
      File "/usr/local/google_appengine/google/appengine/runtime/wsgi.py", line 96, in LoadObject
        __import__(cumulative_path)
      File "/home/apurva/project/flogin/djangoappengine/main/__init__.py", line 66, in <module>
        validate_models()
      File "/home/apurva/project/flogin/djangoappengine/main/__init__.py", line 55, in validate_models
        num_errors = get_validation_errors(s, None)
      File "/home/apurva/project/flogin/django/core/management/validation.py", line 34, in get_validation_errors
        for (app_name, error) in get_app_errors().items():
      File "/home/apurva/project/flogin/django/db/models/loading.py", line 196, in get_app_errors
        self._populate()
      File "/home/apurva/project/flogin/django/db/models/loading.py", line 75, in _populate
        self.load_app(app_name, True)
      File "/home/apurva/project/flogin/django/db/models/loading.py", line 97, in load_app
        app_module = import_module(app_name)
      File "/home/apurva/project/flogin/django/utils/importlib.py", line 42, in import_module
        __import__(name)
    ImportError: No module named oauth2_provider
    

However, I'm unsure on how to add external libraries to my project. So that my
django-nonrel recognises it. I've also tried google's documentation on how to
this i.e.

> Adding Third-party Packages to the Application
>
> You can add any third-party library to your application, as long as it is
> implemented in "pure Python" (no C extensions) and otherwise functions in
> the App Engine runtime environment. The easiest way to manage this is with a
> ./lib directory.
>
> Create a directory named lib in your application root directory:
>
> mkdir lib To tell your app how to find libraries in this directory, create
> (or modify) a file named appengine_config.py in the root of your project,
> then add these lines:
>
> from google.appengine.ext import vendor
>
> £ Add any libraries installed in the "lib" folder. vendor.add('lib') Use pip
> with the -t lib flag to install libraries in this directory:
>
> `$ pip install -t lib gcloud` Note: pip version 6.0.0 or higher is required
> for vendor to work properly.
>
> Tip: the appengine_config.py above assumes that the current working
> directory is where the lib folder is located. In some cases, such as unit
> tests, the current working directory can be different. To avoid errors, you
> can explicity pass in the full path to the lib folder using
> vendor.add(os.path.join(os.path.dirname(os.path.realpath(**file**)), 'lib'))

didn't work either.


Answer: So I had a very similar dilemma. Here is how I solved it:

Followed Google's instructions noted above, using `pip` and a `./lib`
directory. Make sure you have an updated version of `pip`:

    
    
    sudo pip install --upgrade pip
    

Then, because of `pkg_resources` issues, I did this:

    
    
    pip install -t lib setuptools
    

That was necessary, I am just not sure if that was the right place to install
setuptools or not. It certainly worked, though.

Then, I launched the local development server like this, in the project
directory:

    
    
    PYTHONPATH=lib ./manage.py runserver
    

I hope that works for you!

