为什么总是地址'http://127.0.0.1:8050'已经在使用中?

问题描述 投票:0回答:1

我正在做绘图破折号,有时无论我更改使用多少其他端口,它总是给我以下错误。任何原因?我什至关闭 jupyter 笔记本并重新启动它,但仍然遇到同样的错误。所以我对某个地方感到绝望。感谢您的帮助。

OSError:地址“http://127.0.0.1:8052”已在使用中。 尝试将不同的端口传递给 run_server。


if __name__ == "__main__":
    app.run_server(mode='external',debug=True,port=8052)

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_23784/3219569651.py in <module>
      1 if __name__ == "__main__":
      2     #app.run_server(mode='inline',debug=True,port=8051)
----> 3     app.run_server(mode='external',debug=True,port=8052)

~\miniconda3\envs\dash_project\lib\site-packages\jupyter_dash\jupyter_app.py in run_server(self, mode, width, height, inline_exceptions, **kwargs)
    317                 )
    318 
--> 319         wait_for_app()
    320 
    321         if JupyterDash._in_colab:

~\miniconda3\envs\dash_project\lib\site-packages\retrying.py in wrapped_f(*args, **kw)
     47             @six.wraps(f)
     48             def wrapped_f(*args, **kw):
---> 49                 return Retrying(*dargs, **dkw).call(f, *args, **kw)
     50 
     51             return wrapped_f

~\miniconda3\envs\dash_project\lib\site-packages\retrying.py in call(self, fn, *args, **kwargs)
    210                 if not self._wrap_exception and attempt.has_exception:
    211                     # get() on an attempt with an exception should cause it to be raised, but raise just in case
--> 212                     raise attempt.get()
    213                 else:
    214                     raise RetryError(attempt)

~\miniconda3\envs\dash_project\lib\site-packages\retrying.py in get(self, wrap_exception)
    245                 raise RetryError(self)
    246             else:
--> 247                 six.reraise(self.value[0], self.value[1], self.value[2])
    248         else:
    249             return self.value

~\miniconda3\envs\dash_project\lib\site-packages\six.py in reraise(tp, value, tb)
    717             if value.__traceback__ is not tb:
    718                 raise value.with_traceback(tb)
--> 719             raise value
    720         finally:
    721             value = None

~\miniconda3\envs\dash_project\lib\site-packages\retrying.py in call(self, fn, *args, **kwargs)
    198         while True:
    199             try:
--> 200                 attempt = Attempt(fn(*args, **kwargs), attempt_number, False)
    201             except:
    202                 tb = sys.exc_info()

~\miniconda3\envs\dash_project\lib\site-packages\jupyter_dash\jupyter_app.py in wait_for_app()
    310                     host=host, port=port, token=JupyterDash._token
    311                 )
--> 312                 raise OSError(
    313                     "Address '{url}' already in use.\n"
    314                     "    Try passing a different port to run_server.".format(

OSError: Address 'http://127.0.0.1:8052' already in use.
    Try passing a different port to run_server.

python plotly-dash
1个回答
0
投票

作为解决方法,可以在 PlotlyDash

app.run()
命令中添加新端口:

app.run(port=8051)

但是,这并不是那么干净,并且不能解决“挂起”或“剩余”端口的问题...更好的解决方案是识别并杀死剩余进程,从而释放端口。

在 Mac OSX 上,执行以下步骤:

  1. 使用终端中的命令找出端口 8050(或打开/占用的端口)上正在运行的内容:
    lsof -i :8050
  2. 从输出中识别在该端口上运行的 PID(进程 ID)
    lsof
  3. 使用命令
    kill <PID>
  4. 终止进程
© www.soinside.com 2019 - 2024. All rights reserved.