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

Problem while getting started.



  • Hi, I am following the Quickstart section in documentation on Anaconda with python 3.6

    I downloaded manually the file from github for data named "orcl-1995-2014.txt"

    But when I run the sample program given on https://www.backtrader.com/docu/quickstart/quickstart.html#our-first-strategy
    under section Adding a Data Feed¶

    I am getting following error:

    File "C:\dev\Anaconda3\lib\site-packages\backtrader\feeds\yahoo.py", line 128, in _loadline
    dt = date(int(dttxt[0:4]), int(dttxt[5:7]), int(dttxt[8:10]))

    ValueError: invalid literal for int() with base 10: ''

    Please advise, what's wrong.

    Thanks in advance.



  • Although it may not seem obvious to you:

    • If you don't show the code there is little that can be done. Yes, you pointed out that you were following the quickstart guid, but you have probably modified things. At least to find the data feed.

    • You can help if you also show a couple of lines of the actual data downloaded. Because it seems that the data you have has characters which aren't numbers in the datetime part. That's something you can look up yourself.

    To post the code and a fragment of the data and properly format, see at the top of the forum for the 3-ticks hint.



  • Thanks Paska, there was a problem with data file. It works for the first example now. Thanks for the 3 tick hint, I will post code going further....

    Now when I run the last example given on https://www.backtrader.com/docu/quickstart/quickstart.html#our-first-strategy

    I get following warnings in logs...

    C:\dev\Anaconda3\lib\site-packages\backtrader\plot\__init__.py:30: UserWarning: 
    This call to matplotlib.use() has no effect because the backend has already
    been chosen; matplotlib.use() must be called *before* pylab, matplotlib.pyplot,
    or matplotlib.backends is imported for the first time.
    
    The backend was *originally* set to 'module://ipykernel.pylab.backend_inline' by the following code:
      File "C:\dev\Anaconda3\lib\site-packages\spyder\utils\ipython\start_kernel.py", line 241, in <module>
        main()
      File "C:\dev\Anaconda3\lib\site-packages\spyder\utils\ipython\start_kernel.py", line 225, in main
        kernel.initialize()
      File "<decorator-gen-124>", line 2, in initialize
      File "C:\dev\Anaconda3\lib\site-packages\traitlets\config\application.py", line 87, in catch_config_error
        return method(app, *args, **kwargs)
      File "C:\dev\Anaconda3\lib\site-packages\ipykernel\kernelapp.py", line 464, in initialize
        self.init_code()
      File "C:\dev\Anaconda3\lib\site-packages\IPython\core\shellapp.py", line 260, in init_code
        self._run_exec_lines()
      File "C:\dev\Anaconda3\lib\site-packages\IPython\core\shellapp.py", line 286, in _run_exec_lines
        self.shell.run_cell(line, store_history=False)
      File "C:\dev\Anaconda3\lib\site-packages\ipykernel\zmqshell.py", line 533, in run_cell
        return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
      File "C:\dev\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2698, in run_cell
        interactivity=interactivity, compiler=compiler, result=result)
      File "C:\dev\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2808, in run_ast_nodes
        if self.run_code(code, result):
      File "C:\dev\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2862, in run_code
        exec(code_obj, self.user_global_ns, self.user_ns)
      File "<ipython-input-1-e27d371d6baa>", line 1, in <module>
        get_ipython().magic('matplotlib inline')
      File "C:\dev\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2146, in magic
        return self.run_line_magic(magic_name, magic_arg_s)
      File "C:\dev\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2067, in run_line_magic
        result = fn(*args,**kwargs)
      File "<decorator-gen-108>", line 2, in matplotlib
      File "C:\dev\Anaconda3\lib\site-packages\IPython\core\magic.py", line 187, in <lambda>
        call = lambda f, *a, **k: f(*a, **k)
      File "C:\dev\Anaconda3\lib\site-packages\IPython\core\magics\pylab.py", line 99, in matplotlib
        gui, backend = self.shell.enable_matplotlib(args.gui)
      File "C:\dev\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2930, in enable_matplotlib
        pt.activate_matplotlib(backend)
      File "C:\dev\Anaconda3\lib\site-packages\IPython\core\pylabtools.py", line 307, in activate_matplotlib
        matplotlib.pyplot.switch_backend(backend)
      File "C:\dev\Anaconda3\lib\site-packages\matplotlib\pyplot.py", line 229, in switch_backend
        matplotlib.use(newbackend, warn=False, force=True)
      File "C:\dev\Anaconda3\lib\site-packages\matplotlib\__init__.py", line 1305, in use
        reload(sys.modules['matplotlib.backends'])
      File "C:\dev\Anaconda3\lib\importlib\__init__.py", line 166, in reload
        _bootstrap._exec(spec, module)
      File "C:\dev\Anaconda3\lib\site-packages\matplotlib\backends\__init__.py", line 14, in <module>
        line for line in traceback.format_stack()
    
    
      matplotlib.use('TkAgg')
    C:\dev\Anaconda3\lib\site-packages\backtrader\plot\plot.py:127: UserWarning: 
    This call to matplotlib.use() has no effect because the backend has already
    been chosen; matplotlib.use() must be called *before* pylab, matplotlib.pyplot,
    or matplotlib.backends is imported for the first time.
    
    The backend was *originally* set to 'module://ipykernel.pylab.backend_inline' by the following code:
      File "C:\dev\Anaconda3\lib\site-packages\spyder\utils\ipython\start_kernel.py", line 241, in <module>
        main()
      File "C:\dev\Anaconda3\lib\site-packages\spyder\utils\ipython\start_kernel.py", line 225, in main
        kernel.initialize()
      File "<decorator-gen-124>", line 2, in initialize
      File "C:\dev\Anaconda3\lib\site-packages\traitlets\config\application.py", line 87, in catch_config_error
        return method(app, *args, **kwargs)
      File "C:\dev\Anaconda3\lib\site-packages\ipykernel\kernelapp.py", line 464, in initialize
        self.init_code()
      File "C:\dev\Anaconda3\lib\site-packages\IPython\core\shellapp.py", line 260, in init_code
        self._run_exec_lines()
      File "C:\dev\Anaconda3\lib\site-packages\IPython\core\shellapp.py", line 286, in _run_exec_lines
        self.shell.run_cell(line, store_history=False)
      File "C:\dev\Anaconda3\lib\site-packages\ipykernel\zmqshell.py", line 533, in run_cell
        return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
      File "C:\dev\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2698, in run_cell
        interactivity=interactivity, compiler=compiler, result=result)
      File "C:\dev\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2808, in run_ast_nodes
        if self.run_code(code, result):
      File "C:\dev\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2862, in run_code
        exec(code_obj, self.user_global_ns, self.user_ns)
      File "<ipython-input-1-e27d371d6baa>", line 1, in <module>
        get_ipython().magic('matplotlib inline')
      File "C:\dev\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2146, in magic
        return self.run_line_magic(magic_name, magic_arg_s)
      File "C:\dev\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2067, in run_line_magic
        result = fn(*args,**kwargs)
      File "<decorator-gen-108>", line 2, in matplotlib
      File "C:\dev\Anaconda3\lib\site-packages\IPython\core\magic.py", line 187, in <lambda>
        call = lambda f, *a, **k: f(*a, **k)
      File "C:\dev\Anaconda3\lib\site-packages\IPython\core\magics\pylab.py", line 99, in matplotlib
        gui, backend = self.shell.enable_matplotlib(args.gui)
      File "C:\dev\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2930, in enable_matplotlib
        pt.activate_matplotlib(backend)
      File "C:\dev\Anaconda3\lib\site-packages\IPython\core\pylabtools.py", line 307, in activate_matplotlib
        matplotlib.pyplot.switch_backend(backend)
      File "C:\dev\Anaconda3\lib\site-packages\matplotlib\pyplot.py", line 229, in switch_backend
        matplotlib.use(newbackend, warn=False, force=True)
      File "C:\dev\Anaconda3\lib\site-packages\matplotlib\__init__.py", line 1305, in use
        reload(sys.modules['matplotlib.backends'])
      File "C:\dev\Anaconda3\lib\importlib\__init__.py", line 166, in reload
        _bootstrap._exec(spec, module)
      File "C:\dev\Anaconda3\lib\site-packages\matplotlib\backends\__init__.py", line 14, in <module>
        line for line in traceback.format_stack()
    
    
      matplotlib.use('nbagg')
    

    PS: I am using Anaconda and python 3+.

    Not sure, what I am doing wrong now ? Error is coming due to last statement in code...
    '''

    Plot the result

    cerebro.plot()
    

    '''



  • @way-to-java said in Problem while getting started.:

    This call to matplotlib.use() has no effect because the backend has already
    been chosen; matplotlib.use() must be called before pylab, matplotlib.pyplot,
    or matplotlib.backends is imported for the first time.

    The warnings seem clear. You are running the code inside one of the shells that hijack the start of the Python kernel and do horrible things to it.

    Run the code in a normal shell and things will work.

    You can also find references in the community (and in StackOverflow) that multiprocessing is also not compatible with such shells under Windows. I.e.: if you cannot run an optimization using all cores, only 1 core will be available to you under Windows.

    But in any case it doesn't seem like the code is broken and you probably have a plot.



  • @paska-houso

    Thanks, I am experienced Java programmer with very basic understanding of Python. I am using Anaconda, thinking it's a complete Python package.
    Is there a list of recommendations of what to use / not use for me to keep in mind for backtrader, happy to follow them ?



  • Anaconda (as a distribution) and ipython, spyder, etc. (as shells) are ok. Nothing against it. If you want interactivity, saving your work with charts embedded, coming back and making edition in between cells.

    They simply impose restrictions (like the mentioned one for the multiprocessing module under Windows) which you need to be aware of.

    You may want to have a look at PyCharm as integrated environment (execution of scripts inside
    PyCharm* suffers from the same pitfalls as above)

    But serious jobs are better executed from the command line (Cygwin under Windows offers a fantastic Unix-like experience and the WSL is already mature enough for many things)



  • @paska-houso
    Thank You Paska. Downloaded cygwin and try to do what you are suggesting.



  • One thing you can try:

    • cygwin (i.e.: bash in mintty) as the shell
    • Have Anaconda or WinPython installed somewhere
    • Put the location of the python.exe from your chosen distribution in the PATH

    And you get the best of both worlds


Log in to reply
 

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.