首页 > 解决方案 > 使用 TA-lib 遇到 ImportError: cannot import name '__TA_FUNCTION_NAMES__'

问题描述

有人遇到过 Ta-lib 的问题吗?我无法导入任何函数,库似乎安装正确(从 .whl 文件安装,使用 pip 列表检查):

import talib

feature_names = ['5d_close_pct']

# Create moving averages and rsi for timeperiods of 14, 30, 50, 200

list_of_timeperiods = [14, 30, 50, 200]
for n in list_of_timeperiods:

    # Create the moving average indicator and divide by Adj_Close
    returns_data['ma' + str(n)] = talib.SMA(returns_data['Adj_Close'].values, timeperiod=n)/returns_data['Adj_Close']

    # Create the RSI indicator
    returns_data['rsi' + str(n)] = talib.RSI(returns_data['Adj_Close'].values, timeperiod=n)

    # Add RSI and MA to the feature name list
    feature_names = feature_names + ['ma' + str(n), 'rsi' + str(n)]

print (feature_names)

ImportError                               Traceback (most recent call last)
<ipython-input-27-5350715961d9> in <module>
     14 # Another common technical indicator is the relative strength index (RSI)
     15 
---> 16 import talib
     17 
     18 feature_names = ['5d_close_pct']

~\AppData\Local\Programs\Python\Python36\lib\site-packages\talib\__init__.py in <module>
     41         return wrapper
     42 
---> 43 from ._ta_lib import (
     44     _ta_initialize, _ta_shutdown, MA_Type, __ta_version__,
     45     _ta_set_unstable_period as set_unstable_period,

ImportError: cannot import name '__TA_FUNCTION_NAME

标签: pythonta-lib

解决方案


推荐阅读