ibm-cloudwatson-studio

How to install the 'C' dependency ta-lib within Watson Studio?


In a cell in the Jupyter notebook within IBM Cloud Watson Studio I tried:

%pip install TA-Lib

which results in an error:

...

Building wheel for TA-Lib (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /opt/conda/envs/Python-3.7-main/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/wsuser/pip-install-xhysmya0/TA-Lib/setup.py'"'"'; __file__='"'"'/tmp/wsuser/pip-install-xhysmya0/TA-Lib/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/wsuser/pip-wheel-kmjrdwg6
       cwd: /tmp/wsuser/pip-install-xhysmya0/TA-Lib/
  Complete output (27 lines):
  /tmp/wsuser/pip-install-xhysmya0/TA-Lib/setup.py:71: UserWarning: Cannot find ta-lib library, installation may fail.
    warnings.warn('Cannot find ta-lib library, installation may fail.')

...

gcc -pthread -B /opt/conda/envs/Python-3.7-main/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/conda/envs/Python-3.7-main/lib/python3.7/site-packages/numpy/core/include -I/opt/conda/envs/Python-3.7-main/include/python3.7m -c talib/_ta_lib.c -o build/temp.linux-x86_64-3.7/talib/_ta_lib.o
  talib/_ta_lib.c:611:10: fatal error: ta-lib/ta_defs.h: No such file or directory
   #include "ta-lib/ta_defs.h"
            ^~~~~~~~~~~~~~~~~~
  compilation terminated.
  error: command 'gcc' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for TA-Lib



Solution

  • Both ta-lib and the dependency libta-lib are available from conda-forge. Unfortunately, conda takes ages to resolve the environment when you use the conda-forge channel from a Watson Studio notebook. To get things installed quickly, use the direct download URLs. At the time of writing, that would be:

    !conda install https://anaconda.org/conda-forge/libta-lib/0.4.0/download/linux-64/libta-lib-0.4.0-h516909a_0.tar.bz2 https://conda.anaconda.org/conda-forge/linux-64/ta-lib-0.4.19-py37ha21ca33_2.tar.bz2
    

    For updates or other Python versions, check here: