如何为OpenShift Online Next Gen Developer Preview创建requirements.txt文件?

时间:2016-07-11 09:33:20

标签: openshift openshift-nextgen

tl; dr

我正在尝试为本地运行的现有应用程序创建requirements.txt文件。

我想知道requirements.txt文件中应该包含哪些内容。

我这样做是为了让本地应用程序运行:

OpenShift Online (Next Gen) Developer Preview

详细

myapplication.py有许多标准import语句,例如:

#  from python standard library

import os
import re
import StringIO
import json
import ast
import struct
import time
import collections

它还包含import格式的from X import X个语句,例如:

#  additional modules

from bottle import route, post, default_app, template, view, TEMPLATE_PATH, response, request, static_file, install, redirect
# BEGIN pymongo
import pymongo
from bson.json_util import dumps
import gridfs
# END pymongo
import requests
from bs4 import BeautifulSoup
import lxml
import base64
import tldextract
from PIL import Image
import serial

from beaker.middleware import SessionMiddleware
from cork import Cork
from cork.cork import AuthException
from cork.cork import AAAException
from cork.backends import MongoDBBackend

import user_settings (a local .py file)

在本地设置应用程序时,我还必须从Ubuntu软件中心安装这些应用程序:

apache2
virtualenv
mod_wsgi

virtualenv中的pip安装需要这些软件包才能正常工作:

python2.7-dev
libxml2-dev
libxslt1-dev
apache2-dev
zlib1g-dev
libjpeg8-dev

virtualenv被激活时,它们被安装在pip中:

pip install bottle
pip install https://github.com/FedericoCeratto/bottle-cork/archive/master.zip
pip install requests
pip install pymongo==2.8
pip install beautifulsoup4
pip install lxml
pip install Beaker
pip install pillow
pip install tldextract
pip install serial

问题

01)我的requirements.txt文件的内容是否需要如下所示:

pymongo
requests
lxml
tldextract
pyserial
bottle
git+git://github.com/FedericoCeratto/bottle-cork.git#egg=bottle-cork
beautifulsoup4
Beaker
pillow

02) myapplication.py是否仍需要拥有上述定义的导入语句?

03)以下是pip安装在virtualenv中工作所必需的,这些是否已经在OpenShift环境中,如果没有,我该如何添加它们?

python2.7-dev
libxml2-dev
libxslt1-dev
apache2-dev
zlib1g-dev
libjpeg8-dev

04) requirements.txt是否存在于repo目录的顶层目录中?

有关参考和更多信息,这些是在virtualenv中本地运行pip冻结的结果:

(ENV) me@my-computer:/var/www/html/site-name/ENV$ pip freeze
-markerlib==0.0.0
Beaker==1.8.0
beautifulsoup4==4.4.1
bottle==0.12.9
bottle-cork==0.12.0a2
funcsigs==1.0.0
idna==2.1
lxml==3.6.0
ordereddict==1.1
Pillow==3.2.0
pkg-resources==0.0.0
pycrypto==2.6.1
pymongo==2.8
pyserial==3.0.1
requests==2.9.1
tldextract==1.7.5

1 个答案:

答案 0 :(得分:1)

1)这是我最终用于requirements.txt的内容:

pymongo 
requests
lxml
tldextract
pyserial
bottle
# git repo at specific commit - bottle-cork==0.12.0a2
git+git://github.com/FedericoCeratto/bottle-cork.git@557bc6cc249ea8dcb7b76d85bde116527eb41223#egg=bottle-cork
beautifulsoup4
Beaker
pillow

构建似乎有效。

回答我的其他问题:

2)是的,请保留导入语句,如Python应用程序中那样。

3) requirements.txt中的所有软件包安装似乎都在进行,无需明确安装:

python2.7-dev
libxml2-dev
libxslt1-dev
apache2-dev
zlib1g-dev
libjpeg8-dev

4)是的,requirements.txt位于repo的顶层目录中。