调试模式下的 PyDev:NameError: dict_pop 导入 Pandas 或 xarray 时 [英] PyDev in Debug mode: NameError: dict_pop when importing pandas or xarray

查看:68
本文介绍了调试模式下的 PyDev:NameError: dict_pop 导入 Pandas 或 xarray 时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm running code to read data from a NetCDF file from a URL with xarray. When I run this code in Eclipse/PyDev in debug mode I am seeing errors that don't happen when launching as a normal Python run or from the command line or as cells of a Jupyter notebook.

在代码中包含 import xarray 时出现以下错误:

I get the following error when I include an import xarray in my code:

 NameError: name 'dict_pop' is not defined

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

Full stack trace looks like this:

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

我正在使用安装在 Python 3.5.3 (Anaconda) 上的最新/最新版本的 xarray 和 Pandas.

I'm using recent/latest versions of xarray and pandas installed on Python 3.5.3 (Anaconda).

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

I get the same error with an 'import pandas' statement as well, so this may be pandas related instead since xarray depends upon pandas internally.

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

The packages are installed in Anaconda as shown below:

$ 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

同样,我可以在命令行和/或 Jupyter 笔记本中使用导入的 pandas 和 xarray 运行此代码,这仅在我以调试模式在 Eclipse/PyDev 中启动代码时发生(常规 Python 运行)按预期工作).

Again I can run this code with the imports of pandas and xarray with no issue from the command line and/or within a Jupyter notebook, this only happens when I launch the code in Eclipse/PyDev in debug mode (regular Python run works as expected).

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

Example Python code I'm using to test this:

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

谁能给点建议?提前感谢您的任何建议.

Can anyone advise? Thanks in advance for any suggestions.

推荐答案

升级到 5.9.2... 这是解决了新版本的关键问题之一.

Upgrade to 5.9.2... this was one of the critical issues fixed witch prompted the new release.

这篇关于调试模式下的 PyDev:NameError: dict_pop 导入 Pandas 或 xarray 时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆