IDEA/PyCharm Jupyter 运行报错

引言

最近一次运行jupyter时发生错误,AI让修改一些代码,做补丁,但是最后也没有解决。
报错详细:

com.intellij.jupyter.core.jupyter.connections.exceptions.JupyterManagedServerExited: Jupyter server process exited with code 1
Traceback (most recent call last):
  File "<frozen runpy>", line 189, in _run_module_as_main
  File "<frozen runpy>", line 148, in _get_module_details
  File "<frozen runpy>", line 112, in _get_module_details
  File "D:\software\Python\Python312\Lib\site-packages\jupyterlab\__init__.py", line 8, in <module>
    from .handlers.announcements import (
  File "D:\software\Python\Python312\Lib\site-packages\jupyterlab\handlers\announcements.py", line 15, in <module>
    from jupyter_server.base.handlers import APIHandler
  File "D:\software\Python\Python312\Lib\site-packages\jupyter_server\base\handlers.py", line 22, in <module>
    import prometheus_client
  File "D:\software\Python\Python312\Lib\site-packages\prometheus_client\__init__.py", line 3, in <module>
    from . import (
  File "D:\software\Python\Python312\Lib\site-packages\prometheus_client\process_collector.py", line 10, in <module>
    _PAGESIZE = resource.getpagesize()
                ^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'resource' has no attribute 'getpagesize'
    at com.intellij.jupyter.py.connections.managed.server.JupyterServerExecutionImpl$onServerTerminated$1.invokeSuspend(JupyterServerExecutionImpl.kt:260)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:100)
    at com.intellij.openapi.application.impl.EdtCoroutineDispatcher.wrapWithLocking$lambda$3$lambda$2(EdtCoroutineDispatcher.kt:71)
    at com.intellij.openapi.application.WriteIntentReadAction.lambda$run$0(WriteIntentReadAction.java:24)
    at com.intellij.openapi.application.impl.AppImplKt$rethrowCheckedExceptions$2.invoke(appImpl.kt:106)
    at com.intellij.platform.locking.impl.NestedLocksThreadingSupport.doRunWriteIntentReadAction(NestedLocksThreadingSupport.kt:666)
    at com.intellij.platform.locking.impl.NestedLocksThreadingSupport.runPreventiveWriteIntentReadAction(NestedLocksThreadingSupport.kt:640)
    at com.intellij.platform.locking.impl.NestedLocksThreadingSupport.runWriteIntentReadAction(NestedLocksThreadingSupport.kt:633)
    at com.intellij.openapi.application.impl.ApplicationImpl.runWriteIntentReadAction(ApplicationImpl.java:1166)
    at com.intellij.openapi.application.WriteIntentReadAction.compute(WriteIntentReadAction.java:55)
    at com.intellij.openapi.application.WriteIntentReadAction.run(WriteIntentReadAction.java:23)
    at com.intellij.openapi.application.impl.EdtCoroutineDispatcher.wrapWithLocking$lambda$3(EdtCoroutineDispatcher.kt:70)
    at com.intellij.openapi.application.impl.DispatchedRunnable.run(DispatchedRunnable.kt:42)
    at com.intellij.openapi.application.TransactionGuardImpl.runWithWritingAllowed(TransactionGuardImpl.java:240)
    at com.intellij.openapi.application.TransactionGuardImpl.access$100(TransactionGuardImpl.java:26)
    at com.intellij.openapi.application.TransactionGuardImpl$2.run(TransactionGuardImpl.java:222)
    at com.intellij.openapi.application.impl.FlushQueue.runNextEvent(FlushQueue.java:122)
    at com.intellij.openapi.application.impl.FlushQueue.flushNow(FlushQueue.java:43)
    at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:781)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:728)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:722)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87)
    at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:750)
    at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.kt:595)
    at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.kt:488)
    at com.intellij.ide.IdeEventQueue.dispatchEvent$lambda$12$lambda$11$lambda$10$lambda$9(IdeEventQueue.kt:313)
    at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:865)
    at com.intellij.ide.IdeEventQueue.dispatchEvent$lambda$12$lambda$11$lambda$10(IdeEventQueue.kt:312)
    at com.intellij.ide.IdeEventQueueKt.performActivity$lambda$3(IdeEventQueue.kt:974)
    at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:110)
    at com.intellij.ide.IdeEventQueueKt.performActivity(IdeEventQueue.kt:974)
    at com.intellij.ide.IdeEventQueue.dispatchEvent$lambda$12(IdeEventQueue.kt:307)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.kt:347)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
    at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:92)

com.intellij.jupyter.core.jupyter.connections.exceptions.JupyterManagedServerExited: Jupyter server process exited with code 1
Traceback (most recent call last):
  File "<frozen runpy>", line 189, in _run_module_as_main
  File "<frozen runpy>", line 148, in _get_module_details
  File "<frozen runpy>", line 112, in _get_module_details
  File "D:\software\Python\Python312\Lib\site-packages\jupyterlab\__init__.py", line 8, in <module>
    from .handlers.announcements import (
  File "D:\software\Python\Python312\Lib\site-packages\jupyterlab\handlers\announcements.py", line 15, in <module>
    from jupyter_server.base.handlers import APIHandler
  File "D:\software\Python\Python312\Lib\site-packages\jupyter_server\base\handlers.py", line 22, in <module>
    import prometheus_client
  File "D:\software\Python\Python312\Lib\site-packages\prometheus_client\__init__.py", line 3, in <module>
    from . import (
  File "D:\software\Python\Python312\Lib\site-packages\prometheus_client\process_collector.py", line 10, in <module>
    _PAGESIZE = resource.getpagesize()
                ^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'resource' has no attribute 'getpagesize'
    at com.intellij.jupyter.py.connections.managed.server.JupyterServerExecutionImpl.setExceptionallyStoppedState(JupyterServerExecutionImpl.kt:77)
    at com.intellij.jupyter.py.connections.managed.server.JupyterServerExecutionImpl.onServerTerminated(JupyterServerExecutionImpl.kt:263)
    at com.intellij.jupyter.py.connections.managed.server.JupyterServerExecutionImpl.internalStartServer$lambda$3(JupyterServerExecutionImpl.kt:185)
    at com.intellij.jupyter.core.jupyter.connections.managed.JupyterManagedServerProcessHandler$JupyterProcessListener$processTerminated$1.invokeSuspend(JupyterManagedServerProcessHandler.kt:205)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:100)
    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:613)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:1189)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:778)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:765)

image.png

解决方案

检查项目中是否存在resource目录,如果有,重命名或者删除它。

参考:https://github.com/jupyter/notebook/issues/5817
image.png

实际上网上搜出来第一页就有类似的文章,而AI却并没有指出这种可能性。 (有时候不能完全依赖AI)

评论 0

还没有评论,来说点什么吧。

提交后需要审核才会公开。