【问题标题】:Debugger Warning from ipython: Frozen Modules来自 ipython 的调试器警告:冻结模块
【发布时间】:2023-02-05 05:13:00
【问题描述】:

我使用 conda 创建了一个新环境,并想将其添加到 jupyter-lab。我收到关于冻结模块的警告? (如下图)

ipython kernel install --user --name=testi2 

0.00s - Debugger warning: It seems that frozen modules are being used, which may

0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off

0.00s - to python to disable frozen modules.

0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.

Installed kernelspec testi2 in /home/michael/.local/share/jupyter/kernels/testi2

我安装的都是...

ipykernel, ipython, ipywidgets, jupyterlab_widgets, ipympl

Python 版本 3.11.0,Conda 版本 22.11.0

我使用“conda install nodejs -c conda-forge --repodata-fn=repodata.json”来获取最新版本的nodejs

我还尝试将 ipykernel 重新安装到以前的版本 (6.20.1 -> 6.19.2)

【问题讨论】:

    标签: python anaconda conda jupyter-lab


    【解决方案1】:

    这只是调试器无法调试冻结模块的警告。

    在 Python 3.11 中,Python 启动必不可少的核心模块被“冻结”。 ...这减少了模块执行过程中的步骤...现在 Python 3.11 中的解释器启动速度提高了 10-15%。这对使用 Python 的短期运行程序有很大影响。
    https://docs.python.org/3/whatsnew/3.11.html#faster-startup

    调试器不可能调试冻结的模块,因为断点肯定需要文件名
    https://github.com/fabioz/PyDev.Debugger/issues/213#issuecomment-1058247166

    例如。 os.path.realpath.__code__.co_filename 现在是 Python 3.11 中的 '<frozen posixpath>'


    警告中提到了可能的解决方案。

    1. 如果您需要调试这些模块,请将-Xfrozen_modules=off 传递给python
      # ipython kernel install --user --name=testi2
      python -Xfrozen_modules=off -m ipykernel install --user --name=testi2
      
      # jupyter-lab
      python -Xfrozen_modules=off -m jupyterlab
      
      1. 如果你只想抑制警告,设置PYDEVD_DISABLE_FILE_VALIDATION=1
      PYDEVD_DISABLE_FILE_VALIDATION=1 ipython kernel install --user --name=testi2
      
      PYDEVD_DISABLE_FILE_VALIDATION=1 jupyter-lab
      

    【讨论】:

    • 为什么在将 conda 虚拟环境添加到 jupyter lab 时需要对模块进行任何调试?
    • 没有必要。验证在导入时运行:ipkernel.py from .debugger import ...from debugpy.server import ...import debugpy._vendored.force_pydevdpreimport('pydevd', [..., 'pydevd',])import pydevd_file_utils → 文件名验证。
    • 似乎有点愚蠢的验证,不是吗? ofc 模块在检查时将被冻结。
    • ofc 模块在检查时将被冻结。" → 不确定你想在那里说什么。
    • @tumultous_rooster 想澄清一下吗?
    【解决方案2】:

    您遇到的警告消息与在您的环境中使用冻结模块有关,这可能会导致调试器错过断点。推荐的解决方案是将 -Xfrozen_modules=off 传递给 python 命令以禁用冻结模块。

    如果您正在使用 Jupyter Lab 并希望将新环境安装为内核,则可以使用以下命令:

    python -Xfrozen_modules=off -m ipykernel install --user --name=testi2
    

    这应该为新环境安装内核而不会遇到冻结模块警告。请注意,您需要将 testi2 替换为您的环境所需的名称。

    【讨论】:

      猜你喜欢
      • 2019-07-14
      • 2017-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-30
      • 1970-01-01
      相关资源
      最近更新 更多