2017-05-09 3 views
2

Condor를 지원하는 간단한 Python 응용 프로그램을 Heroku에 배포하려고합니다.Heroku에 Anaconda 및 OpenCV와 Docker 응용 프로그램을 배포 할 때 "cv2 == 1.0"요구 사항을 만족하는 버전을 찾을 수 없습니다.

나는 문제없이 Heroku가이 간단한 예제를 배포 할 수 있습니다 https://github.com/heroku-examples/python-miniconda

하지만이 CV2 가져 오기 추가 할 때 그것은 더 이상 작동하지 :

원래 app.py 파일 :

from flask import Flask, jsonify 
from sklearn import datasets, svm 

app = Flask(__name__) 

# Load Dataset from scikit-learn. 
digits = datasets.load_digits() 

@app.route('/') 
def hello(): 
    clf = svm.SVC(gamma=0.001, C=100.) 
    clf.fit(digits.data[:-1], digits.target[:-1]) 
    prediction = clf.predict(digits.data[-1:]) 

    return jsonify({'prediction': repr(prediction)}) 

if __name__ == '__main__': 
    app.run(host='0.0.0.0') 

을 수정 된 app.py 파일 :

from flask import Flask, jsonify, render_template, request, redirect, url_for, send_from_directory 
from sklearn import datasets, svm 
import os 
import json 
import requests 

# browser the file that the user just uploaded 
from werkzeug import secure_filename 
from keras.models import Sequential 
from keras.layers.core import Flatten, Dense, Dropout 
from keras.layers.convolutional import Convolution2D, MaxPooling2D, ZeroPadding2D 
from keras.optimizers import SGD 
from keras.applications.resnet50 import preprocess_input, decode_predictions 
from keras import applications 
import cv2, numpy as np 

app = Flask(__name__) 

# These are the extension that we are accepting to be uploaded 
app.config['ALLOWED_EXTENSIONS'] = set(['png', 'jpg', 'jpeg', 'gif']) 

# For a given file, return whether it's an allowed type or not 
def allowed_file(filename): 
    return '.' in filename and \ 
      filename.rsplit('.', 1)[1] in app.config['ALLOWED_EXTENSIONS'] 

@app.route('/') 
def hello_world(): 
    return 'Hello World!' 

# Route that will process the file upload 
@app.route('/upload', methods=['POST']) 
def upload(): 
    # Get the name of the uploaded file 
    file = request.files['file'] 
    # Check if the file is one of the allowed types/extensions 
    if file and allowed_file(file.filename): 
     # Make the filename safe, remove unsupported chars 
     # filename = secure_filename(file.filename) 
     # Move the file form the temporal folder to 
     # the upload folder we setup 
     # file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) 
     # Redirect the user to the uploaded_file route, which 
     # will basicaly show on the browser the uploaded file 
     file.save(file.filename) 
     im = cv2.resize(cv2.imread(file.filename), (224, 224)).astype(np.float32) 
     im[:,:,0] -= 103.939 
     im[:,:,1] -= 116.779 
     im[:,:,2] -= 123.68 
     im = im.transpose((2,0,1)) 
     im = np.expand_dims(im, axis=0) 
     out = model.predict(im) 
     decoded = decode_predictions(out, top=3)[0] 
     print('Predicted:', decoded) 
     return str(decoded) 

if __name__ == '__main__': 
    # Test pretrained model 
    model = applications.VGG19(include_top=True, weights='imagenet') 
    app.run() 
Could not find a version that satisfies the requirement cv2==1.0 (from -r /tmp/requirements.txt (line 10)) (from versions:) 
No matching distribution found for cv2==1.0 (from -r /tmp/requirements.txt (line 10)) 
The command '/bin/sh -c pip install -qr /tmp/requirements.txt' returned a non-zero code: 1 
! Error: docker build exited with 1 

그래서 그 CV2는 부두 노동자 컨테이너에 누락되어 나타납니다 Heroku가이 수정 된 응용 프로그램을 밀어 때이 오류를받을 수 있습니까? 나는 예제 프로젝트에서 Dockerfile 템플릿에서 "RUN의 CONDA는 -c CONDA - 단조 OpenCV의 설치"이 라인을 추가하지만, 도움이 나던 :

FROM heroku/miniconda 

# Grab requirements.txt. 
ADD ./webapp/requirements.txt /tmp/requirements.txt 

# Install dependencies 
RUN pip install -qr /tmp/requirements.txt 

# Add our code 
ADD ./webapp /opt/webapp/ 
WORKDIR /opt/webapp 

RUN conda install scikit-learn 
RUN conda install -c conda-forge opencv 

CMD gunicorn --bind 0.0.0.0:$PORT wsgi= 

어떤 도움하세요?

답변

1

볼 수있는 오류는 pip가 1.0cv2으로 ppi 색인에 나열된 pip 패키지를 설치할 수 없다는 사실과 관련이 있습니다. 분명히, 그 패키지 설명 "My Blog Distribution Utilities"이며, 현재 어떤 파일과 유사한 오류 볼 이유입니다, https://pypi.python.org/simple/cv2/에 없습니다 :

(test) [email protected]:~$ pip install cv2==1.0 
Collecting cv2==1.0 
    Could not find a version that satisfies the requirement cv2==1.0 (from versions:) 
No matching distribution found for cv2==1.0 

그것은이 원하는 패키지 아니라는 것을 확실히 명백한 것입니다. 그래서 파일에서 cv2==1.0을 제거하십시오 requirements.txt

당신이 정말 찾고있다, 당신은에서 얻을 수 있어야에서 OpenCV에 대한 CONDA 패키지입니다 :

RUN conda install -yc conda-forge opencv 
+0

는 내가 사용하던 맞아 주셔서 감사합니다 pipreqs에 의해 생성 된 requirements.txt 파일과 cv2가 잘못 추가되었습니다. – mkto

관련 문제