Fetching contributors…
Cannot retrieve contributors at this time
171 lines (103 sloc) 7.55 KB
title: Python Buildpack
owner: Buildpacks
<strong><%= modified_date %></strong>
## <a id='pushing_apps'></a> Push an App
Cloud Foundry automatically uses this buildpack if it detects a
`requirements.txt` or `` file in the root directory of your project.
If your Cloud Foundry deployment does not have the Python Buildpack installed, or the installed version is out of date, you can use the latest version by specifying it with the `-b` option when you push your app. For example:
<pre class="terminal">
$ cf push my_app -b
## <a id='supported_versions'></a> Supported Versions
You can find the list of supported Python versions in the [Python buildpack release notes](
## <a id='runtime'></a> Specify a Python Version
You can specify a version of the Python runtime by including it within a `runtime.txt` file. For example:
<pre class="terminal">
$ cat runtime.txt
The buildpack only supports the stable Python versions, which are listed in the `manifest.yml` and [Python buildpack release notes](
To request the latest Python version in a patch line, replace the patch version with `x`: `3.6.x`. To request the latest version in a minor line, replace the minor version: `3.x`.
If you try to use a binary that is not currently supported, staging your app fails and you see the following error message:
<pre class="terminal">
Could not get translated url, exited with: DEPENDENCY_MISSING_IN_MANIFEST: ...
! exit
Staging failed: Buildpack compilation step failed
## <a id='start-command'></a> Specify a Start Command
The Python buildpack does not generate a [default start command](../../devguide/deploy-apps/start-restart-restage.html#first-time) for your applications.
To stage with the Python buildpack and start an application, do one of the following:
- <%= vars.python_cf245only %> Supply a Procfile. For more information about Procfiles, see the [Configuring a Production Server](../prod-server.html) topic. The following example Procfile specifies `gunicorn` as the start command for a web app running on Gunicorn:
web: gunicorn SERVER-NAME:APP-NAME
- Specify a start command with `-c`. The following example specifies `waitress-serve` as the start command for a web app running on Waitress:
<pre class="terminal">
$ cf push python-app -c "waitress-serve --port=$PORT DJANGO-WEB-APP.wsgi:MY-APP"
- Specify a start command in the application manifest by setting the `command` attribute. For more information, see the [Deploying with Application Manifests](../../devguide/deploy-apps/manifest.html#start-commands) topic.
## <a id='vendoring'></a> Vendor App Dependencies
If you are deploying in an environment that is disconnected from the Internet, your application [must vendor its dependencies](
For the Python buildpack, use `pip`:
<pre class="terminal">
$ mkdir -p vendor
# vendors all the pip *.tar.gz into vendor/
$ pip install --download vendor -r requirements.txt --no-binary :all:
`cf push` uploads your vendored dependencies. The buildpack installs them directly from the `vendor/` directory.
<p class="note"><strong>Note</strong>: To ensure proper installation of dependencies, we recommend non-binary vendored dependencies. The above <code>pip install</code> command achieves this.</p>
## <a id='private-repos'></a> Private Dependency Repository
If you deploy apps in an environment that needs to use a private dependency
repository, add the URL of the repository to the `requirements.txt` file in the
following format:
If the private repository uses a custom SSL certificate that is installed on the platform, you may see an error similar to the following:
<pre class="terminal">
Could not fetch URL <span>https:</span>//
There was a problem confirming the ssl certificate:
[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777) - skipping
This error occurs because `pip` does not use system cerificates by default.
To resolve this issue, set the `PIP_CERT` environment variable in the `manifest.yml` file to point to the system certificate store.
For example:
PIP_CERT: /etc/ssl/certs/ca-certificates.crt
## <a id='cfenv'></a> Parse Environment Variables
The `cfenv` package provides access to Cloud Foundry application environment settings by parsing all the relevant environment variables. The settings are returned as a class instance. See []( for more information.
## <a id='miniconda'></a> Miniconda Support <span style="font-size:1rem">(starting in buildpack version <a href="">1.5.6</a>)</span>
To use miniconda instead of pip for installing dependencies, place an `environment.yml` file in the root directory.
For examples, see our sample apps:
* [Using Python 2 with miniconda](
* [Using Python 3 with miniconda](
## <a id='pipenv'></a> Pipenv Support <span style="font-size:1rem">(starting in buildpack version <a href="">1.5.19</a>)</span>
To use [Pipenv]( instead of pip (directly) for installing dependencies, place a `Pipfile` in the root directory. Easiest to let Pipenv generate this for you.
## <a id='nltk'></a> NLTK Support
To use NLTK corpora in your app, you can include an `nltk.txt` file in the root of your application. Each line in the file specifies one dataset to download.
The full list of data sets available this way can be found [on the NLTK website]( The `id` listed for the corpora on that page is the string you should include in your app's `nltk.txt`.
Example `nltk.txt`:
Having an `nltk.txt` file only causes the buildpack to download the corpora. You still must specify NLTK as a dependency of your app if you want to use it to process the corpora files.
## <a id='proxy_support'></a> Proxy Support
If you need to use a proxy to download dependencies during staging, you can set
the `http_proxy` and `https_proxy` environment variables. For more information, see the [Proxy Usage Documentation](../proxy-usage.html).
## <a id='bosh_trusted_cert'></a> BOSH Configured Custom Trusted Certificate Support
Versions of Python 2.7.9 and later use certificates stored in `/etc/ssl/certs`. Your platform operator can configure the platform to [add the custom certificates into the application container](
## <a id='help_support'></a> Help and Support
Join the #buildpacks channel in our [Slack community]( if you need any further assistance.
For more information about using and extending the Python buildpack in Cloud Foundry, see the [python-buildpack GitHub repository](
You can find current information about this buildpack on the [Python buildpack
release page]( in GitHub.