且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 EC2 实例中使用 WSGI 来托管 Flask 应用程序时出现导入问题

更新时间:2021-12-26 02:53:26

经过漫长而痛苦的练习,我终于能够运行我的应用程序. 问题在于在 .wsgi 文件中导入应用程序时构建的 pandas 0.19.2

After a long and painful exercise, I was able to finally get my app running .The issue is with the pandas 0.19.2 built when the application is getting imported in the .wsgi file

解决它从全局级别删除导入并在函数级别插入它们

To resolve it Remove your imports from the global level and insert them at the function level

import pandas as pd
....
@app.route('/getFunction', methods=["GET"])
def sample_get_function():
    movieData=pd.read_csv('someData.csv')

....
@app.route('/getFunction', methods=["GET"])
def sample_get_function():
    import pandas as pd
    movieData=pd.read_csv('someData.csv')

这不是一个很好的解决方案,但它有效

This is not a very good solution but it is working