Resolviendo el problema del error de instalación de TA_Lib en Linux
TA_Lib es la biblioteca de indicadores cuantitativos de Python, que contiene más de 150 indicadores cuantitativos y se utiliza a menudo en análisis cuantitativos.
Este es un contenedor de Python para TA-LIB basado en Cython en lugar de SWIG.
Desde la página de inicio:TA-Lib es ampliamente utilizado por desarrolladores de software comercial que requieren
realizar análisis técnicos de datos del mercado financiero.Incluye más de 150 indicadores como ADX, MACD, RSI, estocástico,
bandas de Bollinger, etc. Reconocimiento de patrones de velas API de código abierto para C/C++,
Java, Perl, Python y .NET 100% administrado
1. Medio ambiente
La versión de conda Python utilizada en Linux es V3.8
# python -V
Python 3.8.13
versión conda V4.5.11
# conda info
active environment : nlp
active env location : /root/anaconda3/envs/nlp
shell level : 2
user config file : /root/.condarc
populated config files : /root/.condarc
conda version : 4.5.11
conda-build version : 3.15.1
python version : 3.7.0.final.0
base environment : /root/anaconda3 (writable)
channel URLs : https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/linux-64
https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/noarch
https://repo.anaconda.com/pkgs/main/linux-64
https://repo.anaconda.com/pkgs/main/noarch
https://repo.anaconda.com/pkgs/free/linux-64
https://repo.anaconda.com/pkgs/free/noarch
https://repo.anaconda.com/pkgs/r/linux-64
https://repo.anaconda.com/pkgs/r/noarch
https://repo.anaconda.com/pkgs/pro/linux-64
https://repo.anaconda.com/pkgs/pro/noarch
package cache : /root/anaconda3/pkgs
/root/.conda/pkgs
envs directories : /root/anaconda3/envs
/root/.conda/envs
platform : linux-64
user-agent : conda/4.5.11 requests/2.28.2 CPython/3.7.0 Linux/3.10.0-327.el7.x86_64 centos/7 glibc/2.17
UID:GID : 0:0
netrc file : None
offline mode : False
2. Mensaje de error
Instalar directamente con pip
# pip install TA_Lib
Looking in indexes: https://pypi.douban.com/simple/
Collecting TA_Lib
Downloading https://pypi.doubanio.com/packages/39/6f/6acaee2eac6afb2cc6a2adcb294080577f9983fbd2726395b9047c4e13ec/TA-Lib-0.4.26.tar.gz (272 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 272.6/272.6 kB 972.6 kB/s eta 0:00:00
Installing build dependencies ... done
Getting requirements to build wheel ... done
Installing backend dependencies ... done
Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: numpy in ./anaconda3/envs/nlp/lib/python3.8/site-packages (from TA_Lib) (1.23.5)
Building wheels for collected packages: TA_Lib
Building wheel for TA_Lib (pyproject.toml) ... error
error: subprocess-exited-with-error
× Building wheel for TA_Lib (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [27 lines of output]
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-cpython-38
creating build/lib.linux-x86_64-cpython-38/talib
copying talib/__init__.py -> build/lib.linux-x86_64-cpython-38/talib
copying talib/abstract.py -> build/lib.linux-x86_64-cpython-38/talib
copying talib/deprecated.py -> build/lib.linux-x86_64-cpython-38/talib
copying talib/stream.py -> build/lib.linux-x86_64-cpython-38/talib
copying talib/test_abstract.py -> build/lib.linux-x86_64-cpython-38/talib
copying talib/test_data.py -> build/lib.linux-x86_64-cpython-38/talib
copying talib/test_func.py -> build/lib.linux-x86_64-cpython-38/talib
copying talib/test_pandas.py -> build/lib.linux-x86_64-cpython-38/talib
copying talib/test_polars.py -> build/lib.linux-x86_64-cpython-38/talib
copying talib/test_stream.py -> build/lib.linux-x86_64-cpython-38/talib
running build_ext
building 'talib._ta_lib' extension
creating build/temp.linux-x86_64-cpython-38
creating build/temp.linux-x86_64-cpython-38/talib
gcc -pthread -B /root/anaconda3/envs/nlp/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/include -I/usr/local/include -I/opt/include -I/opt/local/include -I/opt/homebrew/include -I/opt/homebrew/opt/ta-lib/include -I/tmp/pip-build-env-lmazfngv/normal/lib/python3.8/site-packages/numpy/core/include -I/root/anaconda3/envs/nlp/include/python3.8 -c talib/_ta_lib.c -o build/temp.linux-x86_64-cpython-38/talib/_ta_lib.o
talib/_ta_lib.c:747:28: fatal error: ta-lib/ta_defs.h: No such file or directory
#include "ta-lib/ta_defs.h"
^
compilation terminated.
<string>:77: UserWarning: Cannot find ta-lib library, installation may fail.
error: command '/usr/bin/gcc' failed with exit code 1
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for TA_Lib
Failed to build TA_Lib
ERROR: Could not build wheels for TA_Lib, which is required to install pyproject.toml-based projects
github presenta TA-Lib
Los enlaces de Python originales incluidos en TA-Lib usan SWIG. Desafortunadamente, SWIG es difícil de instalar y no es tan eficiente como se esperaba.
Siga el método de instalación recomendado:
conda install -c conda-forge ta-lib
La instalación fue exitosa y el efecto es el siguiente:
conda install -c conda-forge ta-lib
Solving environment: done
==> WARNING: A newer version of conda exists. <==
current version: 4.5.11
latest version: 23.7.2
Please update conda by running
$ conda update -n base -c defaults conda
## Package Plan ##
environment location: /root/anaconda3/envs/nlp
added / updated specs:
- ta-lib
The following packages will be downloaded:
package | build
---------------------------|-----------------
python_abi-3.8 | 2_cp38 4 KB conda-forge
_libgcc_mutex-0.1 | conda_forge 3 KB conda-forge
libta-lib-0.4.0 | h166bdaf_1 517 KB conda-forge
libuuid-2.32.1 | h7f98852_1000 28 KB conda-forge
libgfortran5-12.2.0 | h337968e_19 1.8 MB conda-forge
bzip2-1.0.8 | h7f98852_4 484 KB conda-forge
_openmp_mutex-4.5 | 2_gnu 23 KB conda-forge
libgfortran-ng-12.2.0 | h69a702a_19 22 KB conda-forge
libblas-3.9.0 |16_linux64_openblas 13 KB conda-forge
libzlib-1.2.12 | h166bdaf_2 63 KB conda-forge
libnsl-2.0.0 | h7f98852_0 31 KB conda-forge
liblapack-3.9.0 |16_linux64_openblas 13 KB conda-forge
libgcc-ng-12.2.0 | h65d4601_19 931 KB conda-forge
libffi-3.4.2 | h7f98852_5 57 KB conda-forge
libgomp-12.2.0 | h65d4601_19 455 KB conda-forge
openssl-3.0.7 | h166bdaf_0 2.8 MB conda-forge
ta-lib-0.4.19 | py38h71d37f0_4 398 KB conda-forge
ca-certificates-2022.9.24 | ha878542_0 150 KB conda-forge
libopenblas-0.3.21 |pthreads_h78a6416_3 10.1 MB conda-forge
python-3.8.13 |ha86cf86_0_cpython 25.2 MB conda-forge
numpy-1.21.4 | py38he2449b9_0 6.2 MB conda-forge
libcblas-3.9.0 |16_linux64_openblas 13 KB conda-forge
------------------------------------------------------------
Total: 49.2 MB
The following NEW packages will be INSTALLED:
_openmp_mutex: 4.5-2_gnu conda-forge
bzip2: 1.0.8-h7f98852_4 conda-forge
libblas: 3.9.0-16_linux64_openblas conda-forge
libcblas: 3.9.0-16_linux64_openblas conda-forge
libgfortran-ng: 12.2.0-h69a702a_19 conda-forge
libgfortran5: 12.2.0-h337968e_19 conda-forge
libgomp: 12.2.0-h65d4601_19 conda-forge
liblapack: 3.9.0-16_linux64_openblas conda-forge
libnsl: 2.0.0-h7f98852_0 conda-forge
libopenblas: 0.3.21-pthreads_h78a6416_3 conda-forge
libta-lib: 0.4.0-h166bdaf_1 conda-forge
libuuid: 2.32.1-h7f98852_1000 conda-forge
libzlib: 1.2.12-h166bdaf_2 conda-forge
numpy: 1.21.4-py38he2449b9_0 conda-forge
python_abi: 3.8-2_cp38 conda-forge
ta-lib: 0.4.19-py38h71d37f0_4 conda-forge
The following packages will be UPDATED:
_libgcc_mutex: 0.1-main --> 0.1-conda_forge conda-forge
libffi: 3.3-he6710b0_2 --> 3.4.2-h7f98852_5 conda-forge
libgcc-ng: 9.1.0-hdf63c60_0 --> 12.2.0-h65d4601_19 conda-forge
openssl: 1.1.1t-h7f8727e_0 --> 3.0.7-h166bdaf_0 conda-forge
python: 3.8.13-h12debd9_0 --> 3.8.13-ha86cf86_0_cpython conda-forge
The following packages will be DOWNGRADED:
ca-certificates: 2023.01.10-h06a4308_0 --> 2022.9.24-ha878542_0 conda-forge
Proceed ([y]/n)? y
Downloading and Extracting Packages
python_abi-3.8 | 4 KB | ######################################################################################### | 100%
_libgcc_mutex-0.1 | 3 KB | ######################################################################################### | 100%
libta-lib-0.4.0 | 517 KB | ######################################################################################### | 100%
libuuid-2.32.1 | 28 KB | ######################################################################################### | 100%
libgfortran5-12.2.0 | 1.8 MB | ######################################################################################### | 100%
bzip2-1.0.8 | 484 KB | ######################################################################################### | 100%
_openmp_mutex-4.5 | 23 KB | ######################################################################################### | 100%
libgfortran-ng-12.2. | 22 KB | ######################################################################################### | 100%
libblas-3.9.0 | 13 KB | ######################################################################################### | 100%
libzlib-1.2.12 | 63 KB | ######################################################################################### | 100%
libnsl-2.0.0 | 31 KB | ######################################################################################### | 100%
liblapack-3.9.0 | 13 KB | ######################################################################################### | 100%
libgcc-ng-12.2.0 | 931 KB | ######################################################################################### | 100%
libffi-3.4.2 | 57 KB | ######################################################################################### | 100%
libgomp-12.2.0 | 455 KB | ######################################################################################### | 100%
openssl-3.0.7 | 2.8 MB | ######################################################################################### | 100%
ta-lib-0.4.19 | 398 KB | ######################################################################################### | 100%
ca-certificates-2022 | 150 KB | ######################################################################################### | 100%
libopenblas-0.3.21 | 10.1 MB | ######################################################################################### | 100%
python-3.8.13 | 25.2 MB | ######################################################################################### | 100%
numpy-1.21.4 | 6.2 MB | ######################################################################################### | 100%
libcblas-3.9.0 | 13 KB | ######################################################################################### | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
3.Verificación
Ver las funciones del método de talib:
import talib
#按组输入talib的方法,返回是字典
content=talib.get_function_groups()
#返回元组
for item in content.items():
#遍历元组
for k in item:
print(k)
Producción:
Cycle Indicators
['HT_DCPERIOD', 'HT_DCPHASE', 'HT_PHASOR', 'HT_SINE', 'HT_TRENDMODE']
Math Operators
['ADD', 'DIV', 'MAX', 'MAXINDEX', 'MIN', 'MININDEX', 'MINMAX', 'MINMAXINDEX', 'MULT', 'SUB', 'SUM']
Math Transform
['ACOS', 'ASIN', 'ATAN', 'CEIL', 'COS', 'COSH', 'EXP', 'FLOOR', 'LN', 'LOG10', 'SIN', 'SINH', 'SQRT', 'TAN', 'TANH']
Momentum Indicators
['ADX', 'ADXR', 'APO', 'AROON', 'AROONOSC', 'BOP', 'CCI', 'CMO', 'DX', 'MACD', 'MACDEXT', 'MACDFIX', 'MFI', 'MINUS_DI', 'MINUS_DM', 'MOM', 'PLUS_DI', 'PLUS_DM', 'PPO', 'ROC', 'ROCP', 'ROCR', 'ROCR100', 'RSI', 'STOCH', 'STOCHF', 'STOCHRSI', 'TRIX', 'ULTOSC', 'WILLR']
Overlap Studies
['BBANDS', 'DEMA', 'EMA', 'HT_TRENDLINE', 'KAMA', 'MA', 'MAMA', 'MAVP', 'MIDPOINT', 'MIDPRICE', 'SAR', 'SAREXT', 'SMA', 'T3', 'TEMA', 'TRIMA', 'WMA']
Pattern Recognition
['CDL2CROWS', 'CDL3BLACKCROWS', 'CDL3INSIDE', 'CDL3LINESTRIKE', 'CDL3OUTSIDE', 'CDL3STARSINSOUTH', 'CDL3WHITESOLDIERS', 'CDLABANDONEDBABY', 'CDLADVANCEBLOCK', 'CDLBELTHOLD', 'CDLBREAKAWAY', 'CDLCLOSINGMARUBOZU', 'CDLCONCEALBABYSWALL', 'CDLCOUNTERATTACK', 'CDLDARKCLOUDCOVER', 'CDLDOJI', 'CDLDOJISTAR', 'CDLDRAGONFLYDOJI', 'CDLENGULFING', 'CDLEVENINGDOJISTAR', 'CDLEVENINGSTAR', 'CDLGAPSIDESIDEWHITE', 'CDLGRAVESTONEDOJI', 'CDLHAMMER', 'CDLHANGINGMAN', 'CDLHARAMI', 'CDLHARAMICROSS', 'CDLHIGHWAVE', 'CDLHIKKAKE', 'CDLHIKKAKEMOD', 'CDLHOMINGPIGEON', 'CDLIDENTICAL3CROWS', 'CDLINNECK', 'CDLINVERTEDHAMMER', 'CDLKICKING', 'CDLKICKINGBYLENGTH', 'CDLLADDERBOTTOM', 'CDLLONGLEGGEDDOJI', 'CDLLONGLINE', 'CDLMARUBOZU', 'CDLMATCHINGLOW', 'CDLMATHOLD', 'CDLMORNINGDOJISTAR', 'CDLMORNINGSTAR', 'CDLONNECK', 'CDLPIERCING', 'CDLRICKSHAWMAN', 'CDLRISEFALL3METHODS', 'CDLSEPARATINGLINES', 'CDLSHOOTINGSTAR', 'CDLSHORTLINE', 'CDLSPINNINGTOP', 'CDLSTALLEDPATTERN', 'CDLSTICKSANDWICH', 'CDLTAKURI', 'CDLTASUKIGAP', 'CDLTHRUSTING', 'CDLTRISTAR', 'CDLUNIQUE3RIVER', 'CDLUPSIDEGAP2CROWS', 'CDLXSIDEGAP3METHODS']
Price Transform
['AVGPRICE', 'MEDPRICE', 'TYPPRICE', 'WCLPRICE']
Statistic Functions
['BETA', 'CORREL', 'LINEARREG', 'LINEARREG_ANGLE', 'LINEARREG_INTERCEPT', 'LINEARREG_SLOPE', 'STDDEV', 'TSF', 'VAR']
Volatility Indicators
['ATR', 'NATR', 'TRANGE']
Volume Indicators
['AD', 'ADOSC', 'OBV']