4

我在这里这里发现了几个关于同一问题的问题

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'

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

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

我仍然得到同样的错误

4

2 回答 2

3

仅供参考

我做了一些挖掘,看起来熊猫改变了他们的 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

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

于 2020-10-23T12:24:19.627 回答
0

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

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

于 2020-12-28T21:57:36.710 回答