AttributeError:“ FrozenImporter”对象没有属性“文件名”

时间:2019-06-25 16:11:10

标签: pyinstaller plotly-dash

使用PyInstaller运行从散点代码生成的exe文件时,我始终收到以下错误。

AttributeError: 'FrozenImporter' object has no attribute 'filename'

进行了一些深入的检查,仅能确定在短划线试图 导入dash_renderer 并从 < em> package.filename

试图添加以下内容,但仍然无法解决

  1. 导入dash_renderer 添加到我的代码中
  2. 将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)

用于生成exe文件的PyInstaller代码

\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文件能够正确启动flask应用程序,并且可以访问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

如何解决此错误?

1 个答案:

答案 0 :(得分:0)

我遇到了相同的错误消息,并且通过更改

解决了该错误消息
if __name__ == "__main__":
    app.run_server(debug=True)

if __name__ == "__main__":
    app.run_server(debug=False)

不确定为什么会发生这种情况,或者不确定是否可以使用debug=False来满足您的需求!也许其他人可以详细说明?