Visual Studio 无法在Anaconda环境下的VS Code中运行Plotly Dash的本地服务器

py49o6xq  于 2023-08-07  发布在  其他
关注(0)|答案(2)|浏览(144)

我正在使用Dash Plotly的应用程序(https://dash.plot.ly/getting-started)教程,它以前工作得很好。现在,我似乎无法启动本地主机服务器,而不会收到以下错误消息:

更新当我通过PyCharm运行测试服务器时,它可以工作,所以不知何故,Anaconda和Jupyter似乎是问题所在。

  1. Running on http://127.0.0.1:8050/
  2. Debugger PIN: 749-807-877
  3. * Serving Flask app "__main__" (lazy loading)
  4. * Environment: production
  5. WARNING: Do not use the development server in a production environment.
  6. Use a production WSGI server instead.
  7. * Debug mode: on
  8. An exception has occurred, use %tb to see the full traceback.
  9. SystemExit: 1

字符串
当我再次尝试运行服务器时,它产生了以下错误:

  1. in
  2. 19
  3. 20 if __name__ == '__main__':
  4. ---> 21 app.run_server(debug=True)
  5. /anaconda3/lib/python3.7/site-packages/dash/dash.py in
  6. run_server(self, port, debug, dev_tools_ui, dev_tools_props_check,
  7. dev_tools_serve_dev_bundles, dev_tools_hot_reload,
  8. dev_tools_hot_reload_interval, dev_tools_hot_reload_watch_interval,
  9. dev_tools_hot_reload_max_retry, dev_tools_silence_routes_logging,
  10. **flask_run_options)
  11. 1501 self.logger.info('Debugger PIN: %s',
  12. debugger_pin)
  13. 1502
  14. -> 1503 self.server.run(port=port, debug=debug,
  15. **flask_run_options)
  16. /anaconda3/lib/python3.7/site-packages/flask/app.py in run(self,
  17. host, port, debug, load_dotenv, **options)
  18. 941
  19. 942 try:
  20. --> 943 run_simple(host, port, self, **options)
  21. 944 finally:
  22. 945 # reset the first request information if the
  23. development server
  24. /anaconda3/lib/python3.7/site-packages/werkzeug/serving.py in
  25. run_simple(hostname, port, application, use_reloader, use_debugger,
  26. use_evalex, extra_files, reloader_interval, reloader_type, threaded,
  27. processes, request_handler, static_files, passthrough_errors,
  28. ssl_context)
  29. 793 s = socket.socket(address_family,
  30. socket.SOCK_STREAM)
  31. 794 s.setsockopt(socket.SOL_SOCKET,
  32. socket.SO_REUSEADDR, 1)
  33. --> 795 s.bind(get_sockaddr(hostname, port,
  34. address_family))
  35. 796 if hasattr(s, 'set_inheritable'):
  36. 797 s.set_inheritable(True)
  37. OSError: [Errno 48] Address already in use
  38. Forums and FAQs
  39. ```import dash
  40. import dash_core_components as dcc
  41. import dash_html_components as html
  42. from dash.dependencies import Input, Output
  43. external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
  44. app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
  45. app.layout = html.Div([
  46. dcc.Input(id='my-id', value='initial value', type='text'),
  47. html.Div(id='my-div')
  48. ])
  49. @app.callback(
  50. Output(component_id='my-div', component_property='children'),
  51. [Input(component_id='my-id', component_property='value')]
  52. )
  53. def update_output_div(input_value):
  54. return 'You\'ve entered "{}"'.format(input_value)
  55. if __name__ == '__main__':
  56. app.run_server(debug=True)```
  57. Running on http://127.0.0.1:8050/
  58. Running on http://127.0.0.1:8050/
  59. Running on http://127.0.0.1:8050/
  60. Running on http://127.0.0.1:8050/
  61. Running on http://127.0.0.1:8050/
  62. Running on http://127.0.0.1:8050/
  63. Running on http://127.0.0.1:8050/
  64. Running on http://127.0.0.1:8050/
  65. Running on http://127.0.0.1:8050/
  66. Debugger PIN: 715-884-879
  67. Debugger PIN: 715-884-879
  68. Debugger PIN: 715-884-879
  69. Debugger PIN: 715-884-879
  70. Debugger PIN: 715-884-879
  71. Debugger PIN: 715-884-879
  72. Debugger PIN: 715-884-879
  73. Debugger PIN: 715-884-879
  74. Debugger PIN: 715-884-879
  75. * Serving Flask app "__main__" (lazy loading)
  76. * Environment: production
  77. WARNING: Do not use the development server in a production environment.
  78. Use a production WSGI server instead.
  79. * Debug mode: on
  80. ---------------------------------------------------------------------------
  81. OSError Traceback (most recent call last)
  82. in
  83. 19
  84. 20 if __name__ == '__main__':
  85. ---> 21 app.run_server(debug=True)
  86. /anaconda3/lib/python3.7/site-packages/dash/dash.py in run_server(self, port, debug, dev_tools_ui, dev_tools_props_check, dev_tools_serve_dev_bundles, dev_tools_hot_reload, dev_tools_hot_reload_interval, dev_tools_hot_reload_watch_interval, dev_tools_hot_reload_max_retry, dev_tools_silence_routes_logging, **flask_run_options)
  87. 1501 self.logger.info('Debugger PIN: %s', debugger_pin)
  88. 1502
  89. -> 1503 self.server.run(port=port, debug=debug, **flask_run_options)
  90. /anaconda3/lib/python3.7/site-packages/flask/app.py in run(self, host, port, debug, load_dotenv, **options)
  91. 941
  92. 942 try:
  93. --> 943 run_simple(host, port, self, **options)
  94. 944 finally:
  95. 945 # reset the first request information if the development server
  96. /anaconda3/lib/python3.7/site-packages/werkzeug/serving.py in run_simple(hostname, port, application, use_reloader, use_debugger, use_evalex, extra_files, reloader_interval, reloader_type, threaded, processes, request_handler, static_files, passthrough_errors, ssl_context)
  97. 793 s = socket.socket(address_family, socket.SOCK_STREAM)
  98. 794 s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  99. --> 795 s.bind(get_sockaddr(hostname, port, address_family))
  100. 796 if hasattr(s, 'set_inheritable'):
  101. 797 s.set_inheritable(True)
  102. OSError: [Errno 48] Address already in use


我检查了所有的论坛,我可以找到这个问题,但我似乎找不到任何解决方案是什么问题。在我擦除硬盘并重新安装Anaconda,Dash和VS代码之前,运行本地服务器工作正常。

xzlaal3s

xzlaal3s1#

Address already in use表示您尝试使用的端口已被另一个应用程序使用。请确保您正确关闭了之前运行过的任何Flask(Dash)服务器,或杀死任何剩余的进程。
如果需要使用其他端口,可以将app.run_server(debug=True)更改为app.run_server(debug=True, port=1337)

9gm1akwq

9gm1akwq2#

我重新启动了我的电脑,它工作了!

相关问题