属性错误:模块“backtrader.cerebro”没有属性“run”

问题描述 投票:0回答:1

标题非常不言自明,我有这个虚拟环境:

D:\EnvIBKRAPI

在此虚拟环境中安装了以下软件包:

弃用:在 d: nvibkrapi\lib\site-packages\ibapi-10.19.1-py3.12.egg 加载 Egg 已弃用。 pip 24.3 将强制执行此行为更改。可能的替代方案是使用 pip 进行软件包安装。可以在 https://github.com/pypa/pip/issues/12330 找到讨论 弃用:在 d: nvibkrapi\lib\site-packages\ibpy-0-py3.12.egg 加载 Egg 已弃用。 pip 24.3 将强制执行此行为更改。可能的替代方案是使用 pip 进行软件包安装。可以在 https://github.com/pypa/pip/issues/12330

找到讨论
  • 软件包/版本

  • 反向交易者/1.9.78.123

  • 轮廓/1.2.0

  • 循环器/0.12.1

  • 活动套件/1.0.1

  • 字体工具/4.44.0

  • ib-insync / 0.9.86

  • ibapi / 10.19.1

  • ibapi / 10.19.1

  • ibapi / 10.19.1

  • IbPy / 0

  • IbPy / 0

  • kiwisolver / 1.4.5

  • matplotlib / 3.8.1

  • nest-asyncio / 1.5.8

  • numpy / 1.26.1

  • 包装/23.2

  • 枕头/10.1.0

  • 点 / 23.3.1

  • pyparsing / 3.1.1

  • python-dateutil / 2.8.2

  • 安装工具/68.2.2

  • 六 / 1.16.0

在此虚拟环境中运行调用 cerebro.run() 的程序时,我收到以下错误消息: AttributeError:模块“backtrader.cerebro”没有属性“run”

我的Python代码:

'''cd /d D: -- EnvIBKRAPI\Scripts\activate.bat   -- cd D:\programmation\IDLEpython\backtrader -- "STRAT2-backtrading-LIVE.py"'''
'''OPEN THIS FILE WITH CMD'''

import backtrader as bt
from backtrader import *
import ibapi

cerebro=bt.cerebro

ibstore = bt.stores.IBStore(port=7496)
data = ibstore.getdata(dataname='PX1')

cerebro.run()

当我在“cerebro”模块中的“cerebro”类中搜索函数“run”时,我确实找到了它并且它存在,但由于某种原因我仍然收到此消息,我认为没有任何其他名为 cerebro 的文件在我的虚拟环境中。

查看我的脑文件内容:

[.....]

    def run(self, **kwargs):
        '''The core method to perform backtesting. Any ``kwargs`` passed to it
        will affect the value of the standard parameters ``Cerebro`` was
        instantiated with.

        If ``cerebro`` has not datas the method will immediately bail out.

        It has different return values:


[.............]

可以在以下位置找到: D:\EnvIBKRAPI\Lib\site-packages acktrader

python virtualenv python-venv interactive-brokers backtrader
1个回答
0
投票

我发现了问题: 当我使用 bt.cerebro 调用 cerebro 时,我使用带有小写 C 的“cerebro”,如果我使用带有大写“C”的“bt.Cerebro”,则它可以工作。

谢谢大家

© www.soinside.com 2019 - 2024. All rights reserved.