简体   繁体   English

使用Heroku在Flask中导入模块错误和NameError

[英]Module import Error and NameError in Flask using Heroku

I do have this issue when deploying a small app to heroku, the requirements.txt is very minimal, the app crash with Cannot import module 'NewsApiClient' when using 将小型应用程序部署到heroku时确实存在此问题,requirements.txt非常小,使用时Cannot import module 'NewsApiClient'导致应用程序崩溃

from newsapi import NewsApiClient

and the app actually start with a 500 Internal Error when using from newsapi import * 并且当from newsapi import *使用时,该应用实际上以500内部错误from newsapi import *

NameError: name 'NewsApiClient' is not defined NameError:未定义名称“ NewsApiClient”

newsapi = NewsApiClient(api_key='xxxxxxxxxx')

What I've done so far is create an empty init file on the root folder 到目前为止,我所做的是在根文件夹上创建一个空的初始化文件

It appears you are importing the incorrect package in your requirements.txt file. 看来您在您的requirements.txt文件中导入了错误的程序包。 You have imported the newsapi package which is different then the python-newsapi package. 您导入的newsapi软件包与python-newsapi软件包不同。

Changing the newsapi==0.1.1 to newsapi-python==0.2.3 should fix your problem with the importing error as long as you reinstall the package dependencies. 只要重新安装软件包依赖项,将newsapi==0.1.1更改为newsapi-python==0.2.3解决导入错误的问题。

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

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