简体   繁体   English

无法使用 Apache 将 sklearn 导入 Google Compute Engine 上的 Flask App

[英]Can’t Import sklearn into Flask App on Google Compute Engine with Apache

I can't import sklearn into the init .py file of a flask app I am running on a Google Compute Engine linux (Ubuntu 14.04) VM.我无法将 sklearn 导入到我在 Google Compute Engine linux (Ubuntu 14.04) VM 上运行的 Flask 应用程序的init .py 文件中。 The example code below works fine if I remove the import sklearn statement but will not work when that statement is included.如果我删除 import sklearn 语句,下面的示例代码可以正常工作,但在包含该语句时将不起作用。 The browser waits for a response from the server unit it times out.浏览器等待来自它超时的服务器单元的响应。 I can run any other web apps on the system as long as they don't use sklearn so I know the server works fine.我可以在系统上运行任何其他网络应用程序,只要它们不使用 sklearn,所以我知道服务器工作正常。

init .py初始化.py

    from flask import Flask
    import sklearn

    app = Flask(__name__)

    @app.route("/")
    def hello():
        return "Test"

    if __name__ == "__main__":
        app.run()

The sklearn library is installed and I can import it and use it without problems in my other python files. sklearn 库已安装,我可以导入它并在其他 python 文件中使用它而不会出现问题。 Other libraries I need also import fine (numpy, pandas, bs4, ect).我需要的其他库也可以很好地导入(numpy、pandas、bs4 等)。 The problem is specific to sklearn and to the init .py file.该问题特定于 sklearn 和init .py 文件。 It doesn't actually throw an error if I run the file from the terminal as it would if I tried to import a library that I didn't have installed.如果我从终端运行文件,它实际上并不会抛出错误,就像我尝试导入我没有安装的库一样。 It just doesn't respond when I try to connect to it through the internet.当我尝试通过互联网连接到它时,它只是没有响应。

There are no other versions of python on the system.系统上没有其他版本的python。 It is just the stock python 2.7 version that came with the linux VM.它只是 linux VM 附带的股票 python 2.7 版本。

The problem I was experiencing was the result of apache not working well the C dependencies in sklearn.我遇到的问题是 apache 不能很好地运行 sklearn 中的 C 依赖项的结果。 More information can be found here ( https://github.com/naturalis/nbclassify/issues/2 ).更多信息可以在这里找到( https://github.com/naturalis/nbclassify/issues/2 )。

The solution:解决方案:

Add this line添加这一行

WSGIApplicationGroup %{GLOBAL}

below this line在这条线之下

WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi

in the Virtual Host config file (step 4 in this tutorial https://www.digitalocean.com/community/tutorials/how-to-deploy-a-flask-application-on-an-ubuntu-vps ).在虚拟主机配置文件中(本教程中的第 4 步https://www.digitalocean.com/community/tutorials/how-to-deploy-a-flask-application-on-an-ubuntu-vps )。

The app now works with no issues.该应用程序现在可以正常运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM