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' object has no attribute 'Cerebro'



  • Hi, I installed backtrader correctly in a new conda enviroment but I am getting this error any solution?
    conda list

    (backtrader) C:\Users\robol>conda list
    # packages in environment at C:\Users\robol\.conda\envs\backtrader:
    #
    # Name                    Version                   Build  Channel
    backports                 1.0                        py_2
    backports-functools-lru-cache 1.5                      pypi_0    pypi
    backports.shutil_get_terminal_size 1.0.0                    py27_2
    backports_abc             0.5              py27h0ec6b72_0
    backtrader                1.9.74.123               pypi_0    pypi
    certifi                   2019.6.16                py27_1
    colorama                  0.4.1                    py27_0
    cycler                    0.10.0                   pypi_0    pypi
    decorator                 4.4.0                    py27_1
    enum34                    1.1.6                    py27_1
    futures                   3.3.0                    py27_0
    ipykernel                 4.10.0                   py27_0
    ipython                   5.8.0                    py27_0
    ipython_genutils          0.2.0            py27hbe997df_0
    jupyter_client            5.3.1                      py_0
    jupyter_core              4.5.0                      py_0
    kiwisolver                1.1.0                    pypi_0    pypi
    libsodium                 1.0.16               h8b3e59e_0
    matplotlib                2.2.4                    pypi_0    pypi
    numpy                     1.16.5                   pypi_0    pypi
    pathlib2                  2.3.4                    py27_0
    pickleshare               0.7.5                    py27_0
    pip                       19.2.2                   py27_0
    prompt_toolkit            1.0.15           py27h3a8ec6a_0
    pygments                  2.4.2                      py_0
    pyparsing                 2.4.2                    pypi_0    pypi
    python                    2.7.16               hcb6e200_0
    python-dateutil           2.8.0                    py27_0
    pytz                      2019.2                   pypi_0    pypi
    pyzmq                     18.1.0           py27hc56fc5f_0
    scandir                   1.10.0           py27h0c8e037_0
    setuptools                41.0.1                   py27_0
    simplegeneric             0.8.1                    py27_2
    singledispatch            3.4.0.3          py27h3f9d112_0
    six                       1.12.0                   pypi_0    pypi
    sqlite                    3.29.0               h0c8e037_0
    tornado                   5.1.1            py27h0c8e037_0
    traitlets                 4.3.2            py27h1b1b3a5_0
    vc                        9                    h7299396_1
    vs2008_runtime            9.00.30729.1         hfaea7d5_1
    wcwidth                   0.1.7            py27hb1a0d82_0
    wheel                     0.33.4                   py27_0
    win_unicode_console       0.5              py27hc037021_0
    wincertstore              0.2              py27hf04cefb_0
    zeromq                    4.3.1                h2880e7c_3
    
    (backtrader) C:\Users\robol>
    

    the code

    from __future__ import (absolute_import, division, print_function,
                            unicode_literals)
    
    import backtrader as bt
    
    if __name__ == '__main__':
        cerebro = bt.Cerebro()
    
        print('Starting Portfolio Value: %.2f' % cerebro.broker.getvalue())
    
        cerebro.run()
    
        print('Final Portfolio Value: %.2f' % cerebro.broker.getvalue())
    

    The error

    ---------------------------------------------------------------------------
    AttributeError                            Traceback (most recent call last)
    <ipython-input-4-bd9375d3f4ab> in <module>()
          5 
          6 if __name__ == '__main__':
    ----> 7     cerebro = bt.Cerebro()
          8 
          9     print('Starting Portfolio Value: %.2f' % cerebro.broker.getvalue())
    
    AttributeError: 'module' object has no attribute 'Cerebro'
    
    

  • administrators

    Yes. Rename your file (this without even having seen how your file is named)



  • Thank you for your response! altough that was not the problem the file name was just untitled. But I installed backtrader the wrong way and the issue is now fixed


  • administrators

    Some people tend to name the script backtrader.py and end up importing the script and not the package.


Log in to reply
 

});