【问题标题】:Pandas not loading in JupyterLab熊猫未在 JupyterLab 中加载
【发布时间】:2019-12-05 02:12:54
【问题描述】:

在 JupyterLab 中使用 Python 3 和 Pandas 从事数据科学项目已有数周时间,没有任何问题。今天我无法通过标准 import pandas as pd 加载熊猫。 (请参阅下面的错误消息)

我已尝试检查以确保我的 Anaconda 环境中安装了 pandas。采购我的 Anaconda 环境后,我运行了 pip listconda list,并且都显示了安装在 Anaconda 环境的包列表中的 pandas 0.25.0。

想知道这是否与最近将 JupyterLab 更新到 1.0.2 版和将 Jupyter Notebook 更新到 6.0.0 版有关?

我希望 import pandas as pd 可以正常工作,但我得到了:

    ---------------------------------------------------------------------------
    UnboundLocalError                         Traceback (most recent call last)
    <ipython-input-2-7dd3504c366f> in <module>
    ----> 1 import pandas as pd

    ~/anaconda3/lib/python3.7/site-packages/pandas/__init__.py in <module>
         40 import pandas.core.config_init
         41 
    ---> 42 from pandas.core.api import *
         43 from pandas.core.sparse.api import *
         44 from pandas.tseries.api import *

    ~/anaconda3/lib/python3.7/site-packages/pandas/core/api.py in <module>
         24 )
         25 from pandas.core.arrays import Categorical, array
    ---> 26 from pandas.core.groupby import Grouper
         27 from pandas.io.formats.format import set_eng_float_format
         28 from pandas.core.index import (Index, CategoricalIndex, Int64Index,

    ~/anaconda3/lib/python3.7/site-packages/pandas/core/groupby/__init__.py in <module>
          1 from pandas.core.groupby.groupby import GroupBy  # noqa: F401
    ----> 2 from pandas.core.groupby.generic import (  # noqa: F401
          3     SeriesGroupBy, DataFrameGroupBy, PanelGroupBy)
          4 from pandas.core.groupby.grouper import Grouper  # noqa: F401

    ~/anaconda3/lib/python3.7/site-packages/pandas/core/groupby/generic.py in <module>
         40 import pandas.core.indexes.base as ibase
         41 from pandas.core.internals import BlockManager, make_block
    ---> 42 from pandas.core.panel import Panel
         43 from pandas.core.series import Series
         44 

    ~/anaconda3/lib/python3.7/site-packages/pandas/core/panel.py in <module>
       1584                   docs={})
       1585 
    -> 1586 ops.add_special_arithmetic_methods(Panel)
       1587 ops.add_flex_arithmetic_methods(Panel)
       1588 Panel._add_numeric_operations()

    ~/anaconda3/lib/python3.7/site-packages/pandas/core/ops/__init__.py in add_special_arithmetic_methods(cls)
        810         special methods will be defined and pinned to this class
        811     """
    --> 812     _, _, arith_method, comp_method, bool_method = _get_method_wrappers(cls)
        813     new_methods = _create_methods(
        814         cls, arith_method, comp_method, bool_method, special=True

    ~/anaconda3/lib/python3.7/site-packages/pandas/core/ops/__init__.py in _get_method_wrappers(cls)
        717         comp_special = _comp_method_FRAME
        718         bool_special = _arith_method_FRAME
    --> 719     return arith_flex, comp_flex, arith_special, comp_special, bool_special
        720 
        721 

    UnboundLocalError: local variable 'arith_flex' referenced before assignment

感谢您的任何帮助或建议。

【问题讨论】:

  • 如果你用 conda 更新了,你还没有 pandas 0.25。但是,如果您使用 pip 更新了 pandas,您可能已经破坏了依赖项。如果您使用的是 conda env,我建议您删除 pandas 并使用 conda 重新安装它。我只对 conda 不提供的软件包使用 pip,所以我不会破坏。
  • @Trenton_M 感谢您的建议。我相信它在本周早些时候与 pandas 0.25 一起工作,但卸载和重新安装值得一试。完成后我会更新。
  • @Trenton_M 感谢您的建议。重新安装 Anaconda 解决了问题。

标签: python pandas anaconda


【解决方案1】:

最终我通过使用this guide 卸载并重新安装 Anaconda 解决了这个依赖问题。这部分符合@Trenton_M 上面的建议/信息,因为重新安装将 Pandas 从 0.25.0 版回滚到 0.24.2 版,同时保留 JupyterLab 1.0.2 版和 Jupyter Notebook 6.0.0 版。

pandas.__version__

输出

'0.24.2'

这是default version listed for Anaconda

【讨论】:

  • 请记住,不要用pip 更新conda 环境中的包。它很可能会破坏您的环境。也就是说,我必须定期重新安装Anaconda,认为它必须更好。我在使用 pip 安装当前不适用于 conda 的软件包时没有遇到任何问题。
  • conda install pandas=0.25.0 如果您想要当前版本。它将从conda-forge 安装,因此您可能需要在.condarc 文件中的channels 下拥有- conda-forge。您可以单独查找。
猜你喜欢
  • 2019-04-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-18
  • 2017-01-06
  • 1970-01-01
  • 2013-07-30
  • 2021-02-20
相关资源
最近更新 更多