python - AttributeError:“FrozenImporter”对象没有属性“文件名”
问题描述
使用 PyInstaller 运行从 plotly-dash 代码生成的 exe 文件时,我不断收到以下错误。
AttributeError: 'FrozenImporter' object has no attribute 'filename'
做了一些深入的检查,只能识别出 dash 尝试导入 dash_renderer并从package.filename行检索文件名时发生的属性错误
尝试添加以下但仍然无法解决
- 将import dash_renderer添加到我的代码中
- 将 dash 和 dash_renderer 包文件夹复制到 dist/{app}/ 文件夹中
我的破折号代码
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.layout = html.Div(children=[
html.H2(children='H-{} Meeting Dashboard'.format("SS"), style={'text-align':'center'}),
html.Div(children=[
html.Div('''Generated on {}'''.format(str(datetime.now())[:19]), style={'text-align':'center', 'font-size':'15px'})
], className='row')]
)
if __name__ == "__main__":
app.run_server(debug=True)
PyInstaller 用于生成 exe 文件的代码
\path\to\python37\python.exe -m PyInstaller app_short.py
运行.exe文件时出错,在下面遇到错误
my\directory>app_short.exe
2019-06-25 23:36:55 Imported all modules
Traceback (most recent call last):
File "app_short.py", line 24, in <module>
File "site-packages\dash\dash.py", line 1476, in run_server
File "site-packages\dash\dash.py", line 1361, in enable_dev_tools
File "site-packages\dash\dash.py", line 1359, in <listcomp>
AttributeError: 'FrozenImporter' object has no attribute 'filename'
[16716] Failed to execute script app_short
运行 app_short.py 文件能够正确启动烧瓶应用程序并且可以访问 html 页面,但 exe 一直显示 AttributeError。
\my\directory>app_short.py
2019-06-25 23:56:47 Imported all modules
Running on http://127.0.0.1:8050/
Debugger PIN: 313-047-004
* Serving Flask app "app_short" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: on
2019-06-25 23:56:51 Imported all modules
Running on http://127.0.0.1:8050/
Debugger PIN: 074-068-565
如何修复此错误?
解决方案
我遇到了同样的错误信息,我通过更改解决了
if __name__ == "__main__":
app.run_server(debug=True)
至
if __name__ == "__main__":
app.run_server(debug=False)
不知道为什么会发生这种情况,或者是否debug=False
可以根据您的需要运行!也许其他人可以详细说明?
推荐阅读
- php - 找不到类“Pbmedia\LaravelFFMpeg\FFMpegServiceProvider\FFMpeg”
- c# - 如果记录的记录超过 50000 条,则获取总记录数
- php - 无法使用 PHP (put request) 更新 CouchDB 文档,一直以“Forbidden”响应:“Invalid Data”
- r - 如何绘制 y=max{g(x),x} 的图
- html - 我想在 HTML 文件中对我的服务人员进行编码,我可以这样做吗?
- javascript - 计算器中的减法和加法结果不正确
- react-native - 在 React Native 中使用密码类型时,文本输入的占位符不支持 RTL
- c++ - 如何匹配通过引用传递给模拟函数的结构字段?
- html5-canvas - 如何在 webgl/opengl 中将纹理划分为瓷砖并显示每个瓷砖的边框?
- c++ - 如何在给定起点和终点的字符串中查找子字符串的出现次数?