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

Cannot import backtrader



  • It seems after I upgrade TA-Lib to 0.4.14, I cannot import backtrader. Below is error message

    (pys) ➜ /Users/hobart : ipython
    imPython 3.6.3 (default, Oct  4 2017, 06:09:38)
    Type 'copyright', 'credits' or 'license' for more information
    IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help.
    por
    In [1]: import backtrader
    ---------------------------------------------------------------------------
    AttributeError                            Traceback (most recent call last)
    <ipython-input-1-6074cc3425cc> in <module>()
    ----> 1 import backtrader
    
    ~/envs/pys/lib/python3.6/site-packages/backtrader/__init__.py in <module>()
         84 from . import timer as timer
         85
    ---> 86 from . import talib as talib
         87
         88 # Load contributed indicators and studies
    
    ~/envs/pys/lib/python3.6/site-packages/backtrader/talib.py in <module>()
         43     # Reverse TA_FUNC_FLAGS dict
         44     R_TA_FUNC_FLAGS = dict(
    ---> 45         zip(talib.abstract.TA_FUNC_FLAGS.values(),
         46             talib.abstract.TA_FUNC_FLAGS.keys()))
         47
    
    AttributeError: module 'talib.abstract' has no attribute 'TA_FUNC_FLAGS'
    
    In [2]: import talib
    
    In [3]: import numpy
    
    In [4]: close = numpy.random.random(100)
       ...: print(close)
       ...: talib.func.EMA(close)
       ...:
    [0.48658111 0.60904357 0.62147432 0.44004752 0.72152203 0.40447694
     0.62992663 0.05292237 0.58165304 0.20155095 0.75575079 0.10174591
     0.29632501 0.30910017 0.85767516 0.64317007 0.64958776 0.91611994
     0.6151113  0.04768506 0.03936707 0.34715809 0.91454819 0.29295831
     0.31359631 0.86264969 0.39093227 0.50784194 0.73060873 0.64893869
     0.89015159 0.3883809  0.12647983 0.45509195 0.22169045 0.51436689
     0.96003853 0.47187102 0.35152709 0.66885533 0.12808871 0.05871258
     0.43275921 0.01570905 0.4997599  0.04186973 0.47195349 0.5048064
     0.90275798 0.05913387 0.71447511 0.64238185 0.53427691 0.66124972
     0.37921765 0.28745235 0.12909667 0.94801479 0.03092563 0.38271452
     0.17982208 0.21395737 0.44207327 0.18252941 0.47804247 0.3301851
     0.12874089 0.34280863 0.17782949 0.15736332 0.30753052 0.37638499
     0.84797322 0.69876274 0.26208841 0.53892864 0.99381914 0.29684256
     0.36565316 0.4033303  0.84659048 0.76722345 0.71053515 0.1864778
     0.82724368 0.56304743 0.79407747 0.06618106 0.63766327 0.831639
     0.18146517 0.94024284 0.44916914 0.58341733 0.09677711 0.84488009
     0.77562232 0.18376314 0.45425217 0.02113227]
    Out[4]:
    array([       nan,        nan,        nan,        nan,        nan,
                  nan,        nan,        nan,        nan,        nan,
                  nan,        nan,        nan,        nan,        nan,
                  nan,        nan,        nan,        nan,        nan,
                  nan,        nan,        nan,        nan,        nan,
                  nan,        nan,        nan,        nan, 0.49966897,
           0.52486139, 0.5160562 , 0.49092224, 0.48861061, 0.47138995,
           0.47416266, 0.50550949, 0.50333927, 0.49354493, 0.50485528,
           0.48054776, 0.45333259, 0.45200527, 0.42385713, 0.42875408,
           0.4037938 , 0.4081912 , 0.41442444, 0.44592983, 0.42097525,
           0.43991073, 0.45297338, 0.45821877, 0.47131754, 0.46537561,
           0.45389669, 0.43294185, 0.46617236, 0.43809193, 0.43451919,
           0.41808712, 0.40491746, 0.40731461, 0.39281234, 0.39831106,
           0.39391583, 0.37680777, 0.37461428, 0.36191849, 0.34872138,
           0.3460639 , 0.3480201 , 0.38027514, 0.40082273, 0.39187213,
           0.40135965, 0.43958284, 0.43037379, 0.42619826, 0.42472291,
           0.45194017, 0.47228103, 0.48765226, 0.46822165, 0.49138436,
           0.49600779, 0.51523809, 0.48626667, 0.49603419, 0.51768611,
           0.49599444, 0.52465563, 0.51978553, 0.52389081, 0.49633509,
           0.51882186, 0.53538963, 0.51270405, 0.50893296, 0.47746195])
    

    TA-Lib (0.4.14)
    backtrader (1.9.59.122)

    Do we have a quick solution for this? Or just my computer has this problem?



  • @hobart-liu said in Cannot import backtrader:

    Do we have a quick solution for this?

    Undo the upgrade?



  • If it is not my own problem, then I am relieved :D


  • administrators

    Having a couple of free minutes, it was easy to see where the problem lies. Check:

    Code reordering has taken place in ta-lib, rendering many of the previously available items inside talib.abstract non-reachable.

    You may open a bug with them if you wish.



  • I have the same problem now, any solution to fix ?



  • Actually, I am not expert of talib. Not sure if I can clearly point out the problem. But I managed to rewrite indicators in backtrader. It is much easier for me. Good platform, Unless some python concept is not consistent. ;-)


  • administrators

    The ta-lib developer has been so kind as to re-expose the interface that made automatic parsing of ta-lib functions possible.

    See:

    Upgrading to 0.4.15 should solve the problem.


Log in to reply
 

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