Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    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'

    General Code/Help
    2
    4
    440
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Luc du Plessis
      Luc du Plessis last edited by

      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'
      
      
      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by backtrader

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

        1 Reply Last reply Reply Quote 0
        • Luc du Plessis
          Luc du Plessis last edited by

          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

          1 Reply Last reply Reply Quote 0
          • B
            backtrader administrators last edited by

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

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors