Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在带有numpy c扩展的gcloud上部署ML模型失败_Python_Numpy_Deployment_Virtualenv_Gcloud - Fatal编程技术网

Python 在带有numpy c扩展的gcloud上部署ML模型失败

Python 在带有numpy c扩展的gcloud上部署ML模型失败,python,numpy,deployment,virtualenv,gcloud,Python,Numpy,Deployment,Virtualenv,Gcloud,我正在尝试在线部署一个简单的机器学习模型,以便其他人可以轻松地在线访问它。我尝试在本地主机上本地部署它,效果很好。所以现在,我正试图使用gcloud将其部署为一个web应用程序 我成功地做到了这一点 ,尽管它不是一个ML模型 这是我的项目目录上的一个视图!请点击查看 我使用的是Mac电脑,所以我的python是2.7,但当我使用Jupyter笔记本电脑时,我也使用python 3.7。我主要通过Anaconda在笔记本上开发我的东西 这是main.py: import numpy as np f

我正在尝试在线部署一个简单的机器学习模型,以便其他人可以轻松地在线访问它。我尝试在本地主机上本地部署它,效果很好。所以现在,我正试图使用gcloud将其部署为一个web应用程序

我成功地做到了这一点 ,尽管它不是一个ML模型

这是我的项目目录上的一个视图!请点击查看

我使用的是Mac电脑,所以我的python是2.7,但当我使用Jupyter笔记本电脑时,我也使用python 3.7。我主要通过Anaconda在笔记本上开发我的东西

这是main.py:

import numpy as np
from flask import Flask, request, jsonify, render_template
import pickle

app = Flask(__name__)
model = pickle.load(open('model.pkl', 'rb'))

@app.route('/')
def home():
    return render_template('index.html')

@app.route('/predict',methods=['POST'])
def predict():

    int_features = [int(x) for x in request.form.values()]
    final_features = [np.array(int_features)]
    prediction = model.predict(final_features)

    output = round(prediction[0], 2)

    return render_template('index.html', prediction_text='The Forecast is  {}'.format(output))

@app.route('/results',methods=['POST'])
def results():

    data = request.get_json(force=True)
    prediction = model.predict([np.array(list(data.values()))])

    output = prediction[0]
    return jsonify(output)

if __name__ == "__main__":
    app.run(debug=True)
这是我的app.yml:

runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /static
  static_dir: static
- url: /.*
  script: main.app

libraries:
  - name: ssl
    version: latest
My appengine_conengine.py:

from google.appengine.ext import vendor
vendor.add('lib')
这是我的requirement.txt

Flask
Werkzeug
numpy
sklearn
然后我运行这个:

pip install -t lib -r requirements.txt
将所需的4个库放入名为lib的文件夹中。我这样做是因为当我在Virtualenv中测试运行main.py时,它需要Flask、numpy和sklearn才能成功地部署在Localhost:5000上

但是,当我跑步时:

gcloud app deploy 
要将我的项目上载并部署到gcloud,它会显示如下错误:

1, in <module>
    import numpy as np
  File "/base/data/home/apps/n~sales-forecast-3mv3/20191110t154452.422348864415547477/lib/numpy/__init__.py", line 142, in <module>
    from . import core
  File "/base/data/home/apps/n~sales-forecast-3mv3/20191110t154452.422348864415547477/lib/numpy/core/__init__.py", line 47, in <module>
    raise ImportError(msg)
ImportError: 

Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
  1. Check that you expected to use Python2.7 from "/base/alloc/tmpfs/dynamic_runtimes/python27g/79cfdbb680326abd/python27/python27_dist/python",
     and that you have no directories in your PATH or PYTHONPATH that can
     interfere with the Python and numpy version "1.17.3" you're trying to use.
  2. If (1) looks fine, you can open a new issue at
     https://github.com/numpy/numpy/issues.  Please include details on:
     - how you installed Python
     - how you installed numpy
     - your operating system
     - whether or not you have multiple versions of Python installed
     - if you built from source, your compiler versions and ideally a build log

- If you're working with a numpy git repository, try `git clean -xdf`
  (removes all files not under version control) and rebuild numpy.

有人能帮忙吗?非常感谢。

您必须在app.yaml中指定numpy库,如下所示:

app.yaml

runtime: python27
api_version: 1
threadsafe: true

handlers:
  - url: /static
    static_dir: static
  - url: /.*
    script: main.app

libraries:
  - name: ssl
    version: latest
  - name: numpy
    version: "1.6.1"

如果您使用Python 3.7安装了Anaconda,请运行以下命令:-conda install scikit learnIf您使用命令Shell:尝试在requirements.txt中添加scipy,install:pip install sklearnTry以运行pip3.7安装-t lib-r requirements.txt。让我知道它是否有效,如果无效,我将进一步帮助您。您可以添加给您的错误以及您认为导致问题的原因吗?谢谢我看到了message.txt文件,我们可以尝试几件事,以找到问题所在,首先,请运行以下命令:pip uninstall sklearn,pip uninstall scikit learn,pip install sklearn。