plotly dash:更改默认端口

plotly dash: change default port

正在关注 plotly dash getting started guide 但在尝试 运行 python app.py 时收到消息:

OSError: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions

似乎默认地址:http://127.0.0.1:8050/ 已被使用。如何更改默认端口才能使其正常工作?

正如我们在Dash.run_server方法定义中看到的,端口可以作为参数传递:

def run_server(self,
               port=8050,
               debug=True,
               threaded=True,
               **flask_run_options):
    self.server.run(port=port, debug=debug, **flask_run_options)

因此,如果您需要使用其他端口:

if __name__ == '__main__':
    app.run_server(debug=True, port=8051) # or whatever you choose

请注意,在 Julia 中,您可以通过在 run_server 参数中指定端口号来更改端口,而无需指定“port=”。例如,

run_server(app, "0.0.0.0", 8000, debug = true)

在 port = 8050 的地方输入你自己的端口号

我在 Jupyter notebook 上 运行 它,我所要做的就是进入运行时并 select 恢复出厂设置运行时,pip 安装所有依赖项(如 jupyter-dash),然后我很高兴去...

您还可以在启动 Dash 应用程序之前在终端中设置环境变量 PORT:

https://github.com/plotly/dash/blob/c77912a3183adfccfd4ef84df91eca7fa9c7d543/dash/_configs.py#L34