-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdependencies.html.md.erb
More file actions
62 lines (42 loc) · 2.41 KB
/
dependencies.html.md.erb
File metadata and controls
62 lines (42 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
---
title: Declare App Dependencies
owner: Tobias Fuhrimann
---
<strong><%= modified_date %></strong>
<%= vars.product_short %> recognizes an app as Python by the existence of a `requirements.txt` file in the root directory. For your own apps, you can create one by running `pip freeze > requirements.txt`.
The demo app you deployed already has a `requirements.txt`, and it looks something like this:
```txt
Flask>=0.11
```
The `requirements.txt` file determines the dependencies that should be installed with your application. When an app is deployed, <%= vars.product_short %> reads this file and installs the appropriate dependencies using the `pip install -r requirements.txt` command.
To do this locally, create a virtualenv for the app:
<pre class="terminal">
$ virtualenv venv
</pre>
Then, activate the virtualenv.
If you are using Windows, run this command:
<pre class="terminal">
> venv\Scripts\activate.bat
</pre>
If you are not using Windows, run this command:
<pre class="terminal">
$ source venv/bin/activate
</pre>
Now run this command in your local directory to install the dependencies, preparing your system for running the app locally:
<pre class="terminal">
$ pip install -r requirements.txt
Collecting Flask>=0.11 (from -r requirements.txt (line 1))
Downloading Flask-0.11.tar.gz (544kB)
...
</pre>
Once dependencies are installed, you will be ready to run your app locally.
Upon running `cf push`, we will also push our whole virtual environment folder `venv`. Since Cloud Foundry runs `pip install -r requirements.txt` anyways, this is redundant and should be omitted to save bandwidth and even more importantly: time. You can create a `.cfignore` file which works just like a `.gitignore` file and which tells Cloud Foundry what files should be excluded when pushing. Let's create a `.cfignore` file and exclude the `venv` folder:
```txt
venv
```
<p class="note">
<strong>Note</strong>: Cloud Foundry uses the latest version of Python 2 by default. To change that, create a <code>runtime.txt</code> file and put the respective version number into it (e.g. <code>python-3.6.1</code>). Be aware however, that Cloud Foundry only accepts the version specified <a href="https://github.com/cloudfoundry/python-buildpack/blob/master/manifest.yml" target="_blank">here</a>.
</p>
<div style="text-align:center;margin:3em;">
<a href="./run-locally.html" class="btn btn-primary">I've installed the App dependencies locally</a>
</div>