A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cloud.google.com/appengine/docs/legacy/standard/python/tools/using-libraries-python-27 below:

Using Python 2 libraries | App Engine standard environment for Python 2

Using Python 2 libraries

Stay organized with collections Save and categorize content based on your preferences.

You can use third-party libraries that are pure Python code with no C extensions, by copying the library into your application directory. If the third-party library is already built-in, bundled with the runtime, you can use the library without copying it into your app.

Third party libraries must be implemented as pure Python code with no C extensions. If copied to your application directory, they count towards file quotas because the library is uploaded to App Engine along with your application code.

Copying a third-party library

To use a third-party library that is not on the list of built-in libraries bundled with the runtime:

  1. Create a directory to store your third-party libraries, such as lib/.

    mkdir lib
    
  2. Use pip (version 6 or later) with the -t <directory> flag to copy the libraries into the folder you created in the previous step. For example:

    pip install -t lib/ <library_name>
    

    Using Homebrew Python on macOS?

    Homebrew issues

    If you are using Homebrew Python on macOS, you might encounter an exception when running pip install -t. This problem is related to a known Homebrew installation issue (see Note on pip install --user) with Homebrew's configuration of Python. To work around this issue, temporarily create a ~/.pydistutils.cfg file in your home directory with the following:

    [install]
    prefix=
    

    Be sure to remove this file after installing packages for your App Engine application, as it will prevent you from being able to install packages outside of this context.

  3. Create a file named appengine_config.py in the same folder as your app.yaml file.

  4. Edit the appengine_config.py file and provide your library directory to the vendor.add() method.

    # appengine_config.py
    from google.appengine.ext import vendor
    
    # Add any libraries install in the "lib" folder.
    vendor.add('lib')
    

    The appengine_config.py file 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 explicitly pass in the full path to the lib folder using:

    vendor.add(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'lib'))
    
Using pip requirements files with copied libraries

pip can read a list of libraries to install from a file, known as a requirements file. Requirements files make it easy to set up a new development environment for your app, and upgrade to new versions of libraries.

A requirements file is a text file with one line per library, listing the package name and optionally the version for the package (defaults to latest):

Flask==0.10
Markdown==2.5.2
google-api-python-client

To install the libraries from a requirements file, use the -r flag in addition to the -t lib flag:

pip install -t lib -r requirements.txt
Using a built-in third-party library bundled with the runtime

If the third-party library is on the list of built-in libraries bundled with the App Engine Python runtime, you only have to specify it under the libraries directive in the app.yaml, for example:

libraries:
- name: PIL
  version: "1.1.7"
- name: webob
  version: "1.1.1"

App Engine automatically provides the requested libraries during deployment.

Using built-in bundled libraries with the local development server

Many of the built-in libraries provided by the runtime are automatically available to the local development server. In order to install some libraries locally, you must run gcloud components install app-engine-python-extras. If the local development server detects that this component is needed, it will prompt you to install it. The following built-in libraries must be installed locally before you can use them with the local development server:

You can use the pip command to install all of these packages from the Python package index (PyPI).

sudo pip install lxml==2.3.5

Depending on your platform, you might need to install build support tools and Python sources to install these libraries.

The development server uses the package version you have installed locally regardless of the version specified in app.yaml. If you want, set up a virtualenv for your project to provide the exact package version. Note that the virtualenv is only used for these binary packages locally and will not be made available to your application once deployed. To add additional third-party libraries, use the method described in Installing a library.

Using Django in the local development server Warning: Support for Django versions 1.2 and 1.3 is deprecated and will be removed. See the Django 1.2, 1.3 Turndown document for details and timetable.

Django is a full-featured web application framework for Python. It provides a full stack of interchangeable components, including dispatch, views, middleware, and templating components, and many others.

The Django data modeling interface is not compatible with the App Engine datastore. You can use the App Engine data modeling libraries (db or ndb) in your Django applications. However, third-party Django applications that use the Django data modeling interface, most notably Django's Admin application, might not directly work with App Engine.

The Datastore modeling library (DB) is the default. To use Django with the NDB storage API instead, add 'google.appengine.ext.ndb.django_middleware.NdbDjangoMiddleware', to the MIDDLEWARE_CLASSES entry in your Django settings.py file. It's a good idea to insert it in front of any other middleware classes, since some other middleware might make datastore calls and those won't be handled properly if that middleware is invoked before this middleware. You can learn more about Django middleware in the project documentation.

To enable Django in your app, specify the WSGI application and Django library in app.yaml:

...
handlers:
- url: /.*
  script: main.app  # a WSGI application in the main module's global scope

libraries:
- name: django
  version: "1.4"

The DJANGO_SETTINGS_MODULE environment variable must be set to the name of your Django settings module, typically 'settings', before packages are imported.

If your Django settings module is something other than settings.py, set the DJANGO_SETTINGS_MODULE environment variable accordingly either in your app.yaml file:

env_variables:
  DJANGO_SETTINGS_MODULE: 'myapp.settings'

Or in your Python code:

import os
# specify the name of your settings module
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'

import django.core.handlers.wsgi
app = django.core.handlers.wsgi.WSGIHandler()
Using matplotlib in the local development server Note: The experimental release of matplotlib is not supported on the development server. You can still add matplotlib to the libraries list, but it will raise an ImportError exception when imported.

Matplotlib is a plotting library that produces graphs and figures in a variety of image formats. On App Engine, the interactive modes of matplotlib are not supported, and a number of other features are also unavailable. This means you cannot use pyplot.show() as many matplotlib tutorials suggest. Instead, you should use pyplot.savefig() to write image data to the output stream, a cStringIO.StringIO instance, or the Google Cloud Storage using the Cloud Storage Client Library.

Matplotlib allows extensive customization through the use of the matplotlibrc configuration file, which should be placed in the application's top-level directory. Alternatively, you can set the MATPLOTLIBRC environment variable to a path relative to your application's directory.

The default backend is AGG, which allows writing files of all supported formats: PNG (the default format), RAW, PS, PDF, SVG and SVGZ. If you make the PIL library available by adding PIL to the libraries section of app.yaml, then the AGG backend will automatically support writing JPEG and TIFF image formats as well.

Matplotlib comes with a number of fonts which are automatically available. You can use custom fonts by uploading them in TTF format along with your application, and setting the TTFPATH environment variable to the path where they are located, relative to your application's directory. For more information, see the app.yaml reference.

A number of matplotlib features are not supported on App Engine. In particular:

Note: The pylab and matplotlib.pyplot modules are stateful and not thread safe. If you use them on App Engine, you must set threadsafe: false in app.yaml, and be aware that the plotter state will be preserved between requests on the same instance. For example, you will need to call pyplot.clf() at the beginning of each request to ensure that previous plots are not visible. It is recommended that you use the thread-safe object-oriented API instead of the stateful pyplot API. What's next

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-07-09 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-07-09 UTC."],[[["Third-party Python libraries without C extensions can be used by copying them into your application directory, but these libraries will count towards file quotas as they are uploaded to App Engine."],["To use a third-party library that is not built-in, create a directory like `lib/`, use `pip` to copy the libraries there, and then modify the `appengine_config.py` file to include your library directory."],["For built-in libraries, you can directly specify them under the `libraries` directive in the `app.yaml` file, allowing App Engine to automatically provide them during deployment."],["The local development server requires the installation of specific components (`gcloud components install app-engine-python-extras`) to use some built-in libraries, like `lxml`, `matplotlib`, or `numpy`."],["Django, which is a full-featured web application framework for Python, can be enabled by specifying the WSGI application and Django library in `app.yaml`, while also setting the `DJANGO_SETTINGS_MODULE` environment variable."]]],[]]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4