运行Dash应用程序时名称或服务未知

2024-10-02 12:37:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我的设置非常简单,但无法运行。我怀疑它与服务器地址有关(我认为应该是https://127.0.0.1:8050),但不知道如何更改它。非常感谢您的建议。 -设置虚拟环境并安装dash(使用pip install dash)。它还安装了flask

我的应用程序基本设置:

import dash
import dash_html_components as html

app = dash.Dash()

app.layout = html.Div(
    html.H1(children="Hello World!")
)

if __name__ == '__main__':
    app.run_server(debug=True)

当我在终端中运行我的应用程序时,我得到以下错误:

(Dash) rene@ideapad:~/Projects/Dash$ python my_app.py 
Running on http://x86_64-conda_cos6-linux-gnu:8050/
Debugger PIN: 287-942-334
 * Serving Flask app "my_app" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
Traceback (most recent call last):
  File "my_app.py", line 12, in <module>
    app.run_server(debug=True)
  File "/home/rene/Environments/Dash/lib/python3.7/site-packages/dash/dash.py", line 1973, in run_server
    self.server.run(host=host, port=port, debug=debug, **flask_run_options)
  File "/home/rene/Environments/Dash/lib/python3.7/site-packages/flask/app.py", line 990, in run
    run_simple(host, port, self, **options)
  File "/home/rene/Environments/Dash/lib/python3.7/site-packages/werkzeug/serving.py", line 1030, in run_simple
    s.bind(server_address)
socket.gaierror: [Errno -2] Name or service not known

Tags: runinpydebugappflaskservermy
1条回答
网友
1楼 · 发布于 2024-10-02 12:37:57

我通过手动设置主机和端口解决了此问题:

if __name__ == '__main__':
    app.run_server(host='127.0.0.1', port='8050', debug=True)

但我仍然不知道它为什么开始使用http://x86_64-conda_cos6-linux-gnu:8050

有什么建议吗

相关问题 更多 >

    热门问题