PyDev in Debug mode: NameError: dict_pop when importing pandas or xarray

PyDev in Debug mode: NameError: dict_pop when importing pandas or xarray

我正在使用 运行ning 代码来使用 xarray 从 URL 的 NetCDF 文件中读取数据。当我在调试模式下 运行 Eclipse/PyDev 中的此代码时,我看到在作为正常 Python 运行 或从命令行或作为单元格启动时不会发生的错误Jupyter 笔记本。

当我在我的代码中包含导入 xarray 时出现以下错误:

 NameError: name 'dict_pop' is not defined

完整的堆栈跟踪如下所示:

pydev debugger: starting (pid: 4004)
URL: https://www.ncei.noaa.gov/data/nclimgrid/nclimgrid_prcp.nc
Traceback (most recent call last):
  File "_pydevd_bundle\pydevd_cython_win32_35_64.pyx", line 741, in _pydevd_bundle.pydevd_cython_win32_35_64.PyDBFrame.trace_dispatch (_pydevd_bundle/pydevd_cython_win32_35_64.c:15515)
  File "_pydevd_bundle\pydevd_cython_win32_35_64.pyx", line 254, in _pydevd_bundle.pydevd_cython_win32_35_64.PyDBFrame.do_wait_suspend (_pydevd_bundle/pydevd_cython_win32_35_64.c:5631)
  File "C:\User Programs\eclipse\neon\plugins\org.python.pydev_5.9.0.201708101613\pysrc\pydevd.py", line 764, in do_wait_suspend
    self._activate_mpl_if_needed()
  File "C:\User Programs\eclipse\neon\plugins\org.python.pydev_5.9.0.201708101613\pysrc\pydevd.py", line 415, in _activate_mpl_if_needed
    activate_function = dict_pop(self.mpl_modules_for_patching, module)
NameError: name 'dict_pop' is not defined
2017-08-16  15:25:06 ERROR Failed to complete ERROR
Traceback (most recent call last):
  File "C:\home\git\indices_github\process_xarray.py", line 27, in <module>
    ncdata = url.read()
  File "C:\home\git\indices_github\process_xarray.py", line 27, in <module>
    ncdata = url.read()
  File "_pydevd_bundle\pydevd_cython_win32_35_64.pyx", line 982, in _pydevd_bundle.pydevd_cython_win32_35_64.SafeCallWrapper.__call__ (_pydevd_bundle/pydevd_cython_win32_35_64.c:19346)
  File "_pydevd_bundle\pydevd_cython_win32_35_64.pyx", line 498, in _pydevd_bundle.pydevd_cython_win32_35_64.PyDBFrame.trace_dispatch (_pydevd_bundle/pydevd_cython_win32_35_64.c:18639)
  File "_pydevd_bundle\pydevd_cython_win32_35_64.pyx", line 750, in _pydevd_bundle.pydevd_cython_win32_35_64.PyDBFrame.trace_dispatch (_pydevd_bundle/pydevd_cython_win32_35_64.c:15669)
  File "_pydevd_bundle\pydevd_cython_win32_35_64.pyx", line 741, in _pydevd_bundle.pydevd_cython_win32_35_64.PyDBFrame.trace_dispatch (_pydevd_bundle/pydevd_cython_win32_35_64.c:15515)
  File "_pydevd_bundle\pydevd_cython_win32_35_64.pyx", line 254, in _pydevd_bundle.pydevd_cython_win32_35_64.PyDBFrame.do_wait_suspend (_pydevd_bundle/pydevd_cython_win32_35_64.c:5631)
  File "C:\User Programs\eclipse\neon\plugins\org.python.pydev_5.9.0.201708101613\pysrc\pydevd.py", line 764, in do_wait_suspend
    self._activate_mpl_if_needed()
  File "C:\User Programs\eclipse\neon\plugins\org.python.pydev_5.9.0.201708101613\pysrc\pydevd.py", line 415, in _activate_mpl_if_needed
    activate_function = dict_pop(self.mpl_modules_for_patching, module)
NameError: name 'dict_pop' is not defined
Traceback (most recent call last):
  File "C:\User Programs\eclipse\neon\plugins\org.python.pydev_5.9.0.201708101613\pysrc\pydevd.py", line 1621, in <module>
    main()
  File "C:\User Programs\eclipse\neon\plugins\org.python.pydev_5.9.0.201708101613\pysrc\pydevd.py", line 1615, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "C:\User Programs\eclipse\neon\plugins\org.python.pydev_5.9.0.201708101613\pysrc\pydevd.py", line 1022, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:\User Programs\eclipse\neon\plugins\org.python.pydev_5.9.0.201708101613\pysrc\_pydev_imps\_pydev_execfile.py", line 25, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:\home\git\indices_github\process_xarray.py", line 27, in <module>
    ncdata = url.read()
  File "C:\home\git\indices_github\process_xarray.py", line 27, in <module>
    ncdata = url.read()
  File "_pydevd_bundle\pydevd_cython_win32_35_64.pyx", line 982, in _pydevd_bundle.pydevd_cython_win32_35_64.SafeCallWrapper.__call__ (_pydevd_bundle/pydevd_cython_win32_35_64.c:19346)
  File "_pydevd_bundle\pydevd_cython_win32_35_64.pyx", line 498, in _pydevd_bundle.pydevd_cython_win32_35_64.PyDBFrame.trace_dispatch (_pydevd_bundle/pydevd_cython_win32_35_64.c:18639)
  File "_pydevd_bundle\pydevd_cython_win32_35_64.pyx", line 750, in _pydevd_bundle.pydevd_cython_win32_35_64.PyDBFrame.trace_dispatch (_pydevd_bundle/pydevd_cython_win32_35_64.c:15669)
  File "_pydevd_bundle\pydevd_cython_win32_35_64.pyx", line 741, in _pydevd_bundle.pydevd_cython_win32_35_64.PyDBFrame.trace_dispatch (_pydevd_bundle/pydevd_cython_win32_35_64.c:15515)
  File "_pydevd_bundle\pydevd_cython_win32_35_64.pyx", line 254, in _pydevd_bundle.pydevd_cython_win32_35_64.PyDBFrame.do_wait_suspend (_pydevd_bundle/pydevd_cython_win32_35_64.c:5631)
  File "C:\User Programs\eclipse\neon\plugins\org.python.pydev_5.9.0.201708101613\pysrc\pydevd.py", line 764, in do_wait_suspend
    self._activate_mpl_if_needed()
  File "C:\User Programs\eclipse\neon\plugins\org.python.pydev_5.9.0.201708101613\pysrc\pydevd.py", line 415, in _activate_mpl_if_needed
    activate_function = dict_pop(self.mpl_modules_for_patching, module)
NameError: name 'dict_pop' is not defined

我正在使用 recent/latest 版本的 xarray 和 pandas 安装在 Python 3.5.3 (Anaconda) 上。

我在 'import pandas' 语句中也遇到了同样的错误,所以这可能与 pandas 相关,因为 xarray 在内部依赖于 pandas。

包安装在 Anaconda 中,如下所示:

$ conda list pandas
# packages in environment at C:\home\Anaconda3:
#
pandas                    0.20.3                   py35_1    conda-forge

$ conda list xarray
# packages in environment at C:\home\Anaconda3:
#
xarray                    0.9.6                    py35_0    conda-forge

再次,我可以 运行 导入 pandas 和 xarray 的代码,在 Jupyter 笔记本中从命令行 and/or 没有问题,这只发生在我启动Eclipse/PyDev 中的代码在调试模式下(常规 Python 运行 按预期工作)。

示例 Python 我用来测试的代码:

import sys
import xarray as xr

if __name__ == '__main__':

    try:

        # get the command line arguments
        input_netcdf_url = sys.argv[1]
        ds = xr.open_dataset(input_netcdf_url)
                
    except:
    
        raise

接下来我可以尝试什么?

升级到 5.9.2...这是修复的关键问题之一 促使发布新版本。