For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

AttributeError: module 'backtrader' has no attribute 'Cerebro'



  • Initially it was working fine, all of sudden it is raising issue ...now trying on example code but the same error

    from datetime import datetime
    import backtrader as bt

    class SmaCross(bt.SignalStrategy):
    def init(self):
    sma1, sma2 = bt.ind.SMA(period=10), bt.ind.SMA(period=30)
    crossover = bt.ind.CrossOver(sma1, sma2)
    self.signal_add(bt.SIGNAL_LONG, crossover)

    cerebro = bt.Cerebro()
    cerebro.addstrategy(SmaCross)

    data0 = bt.feeds.YahooFinanceData(dataname='MSFT', fromdate=datetime(2011, 1, 1),
    todate=datetime(2012, 12, 31))
    cerebro.adddata(data0)

    cerebro.run()
    cerebro.plot()



  • C:\Server\Kite Development\BackTrader>python signal.py
    Traceback (most recent call last):
    File "signal.py", line 2, in <module>
    import backtrader as bt
    File "C:\Program Files\Python37\lib\site-packages\backtrader_init_.py", line 62, in <module>
    from .cerebro import *
    File "C:\Program Files\Python37\lib\site-packages\backtrader\cerebro.py", line 27, in <module>
    import multiprocessing
    File "C:\Program Files\Python37\lib\multiprocessing_init_.py", line 16, in <module>
    from . import context
    File "C:\Program Files\Python37\lib\multiprocessing\context.py", line 5, in <module>
    from . import process
    File "C:\Program Files\Python37\lib\multiprocessing\process.py", line 18, in <module>
    import signal
    File "C:\Server\Kite Development\BackTrader\signal.py", line 10, in <module>
    cerebro = bt.Cerebro()
    AttributeError: module 'backtrader' has no attribute 'Cerebro'

    C:\Server\Kite Development\BackTrader>python --version
    Python 3.7.5


  • administrators

    @Ramesh-Gangappa said in AttributeError: module 'backtrader' has no attribute 'Cerebro':

    C:\Server\Kite Development\BackTrader>python signal.py
    Traceback (most recent call last):
    File "signal.py", line 2, in <module>

    @Ramesh-Gangappa said in AttributeError: module 'backtrader' has no attribute 'Cerebro':

    File "C:\Program Files\Python37\lib\multiprocessing\process.py", line 18, in <module>
    import signal

    Your module has the same name as something which Python internals are trying to import. I actually fear you have misplaced things, but the safest bet: rename your script.



  • Getting same error with module name change. I have reinstalled Python from the scratch, now problem is resolved. Thank you


Log in to reply
 

});