【问题标题】:ModuleNotFoundError: No module named 'pandas._libs.tslibs.frequencies'ModuleNotFoundError:没有名为“pandas._libs.tslibs.frequencies”的模块
【发布时间】:2021-02-06 09:13:00
【问题描述】:

我发现了几个关于同一问题的问题herehere

from pyfinance.ols import PandasRollingOLS

我收到以下错误:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/pyfinance/utils.py", line 78, in <module>
    from pandas.tseries.frequencies import FreqGroup, get_freq_code
ImportError: cannot import name 'FreqGroup' from 'pandas.tseries.frequencies' (/usr/local/lib/python3.8/site-packages/pandas/tseries/frequencies.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python3.8/site-packages/pyfinance/__init__.py", line 32, in <module>
    from .returns import TFrame, TSeries  # noqa
  File "/usr/local/lib/python3.8/site-packages/pyfinance/returns.py", line 42, in <module>
    from pyfinance import ols, utils
  File "/usr/local/lib/python3.8/site-packages/pyfinance/ols.py", line 15, in <module>
    from pyfinance import utils
  File "/usr/local/lib/python3.8/site-packages/pyfinance/utils.py", line 80, in <module>
    from pandas._libs.tslibs.frequencies import FreqGroup, get_freq_code
ModuleNotFoundError: No module named 'pandas._libs.tslibs.frequencies'

我尝试卸载并重新安装 pandas 版本 1.1.3、1.1.2、1.1.1,但它们都不起作用,我只是得到同样的错误,然后我尝试以以下方式构建 pandas:

!python setup.py build_ext --inplace --force

我仍然遇到同样的错误

【问题讨论】:

    标签: python pandas pandas-rolling


    【解决方案1】:

    仅供参考

    我做了一些挖掘,看起来熊猫改变了他们的 api,这导致了上面提到的错误。我修改了源代码并包含了pyfinance/utils.py中的正确导入:

    在第 77 行更改为:

    try:
        from pandas.tseries.frequencies import FreqGroup, get_freq_code
    except ImportError:  # 0.24+, or somewhere around then
        from pandas._libs.tslibs.frequencies import FreqGroup, get_freq_code
    

    try:
        from pandas.tseries.frequencies import FreqGroup, get_freq_code
    except ImportError:
        from pandas._libs.tslibs.dtypes import FreqGroup
        from pandas.tests.tslibs.test_period_asfreq import get_freq_code
    

    我创建了一个拉取请求here 如果你遇到同样的问题,你可以克隆并安装我的fork

    【讨论】:

      【解决方案2】:

      确保您拥有正确版本的 pyfinance。安装 0.1.3 解决了我的问题。

      https://pypi.org/project/pyfinance/0.1.3/

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-09-02
        • 2018-05-16
        • 1970-01-01
        • 2023-02-09
        • 2019-02-13
        • 1970-01-01
        • 2019-04-12
        • 2020-12-02
        相关资源
        最近更新 更多