JD_BNL
JD_BNL

Reputation: 105

How to install Talib (on windows machine) in colab (2022-12)?

Yesterday I tried to run a python code which contains a talib package. The package failed to run in colab, ModuleNotFoundError: No module named 'talib'

I used this code, which normally worked, but after yesterday it didn't.

url = 'https://anaconda.org/conda-forge/libta-lib/0.4.0/download/linux-64/libta-lib-0.4.0-h516909a_0.tar.bz2'
!curl -L $url | tar xj -C /usr/lib/x86_64-linux-gnu/ lib --strip-components=1
url = 'https://anaconda.org/conda-forge/ta-lib/0.4.19/download/linux-64/ta-lib-0.4.19-py37ha21ca33_2.tar.bz2'
!curl -L $url | tar xj -C /usr/local/lib/python3.7/dist-packages/ lib/python3.7/site-packages/talib --strip-components=3

The idea is to install the following items:

import talib as ta
from talib import RSI, BBANDS, MACD

I tried this as well, without succes:

!pip install TA-Lib as ta
from TA-Lib import RSI, BBANDS, MACD

Does someone know how to install this package in colab?

Upvotes: 1

Views: 2994

Answers (1)

Timeless
Timeless

Reputation: 37747

Since Google Colab is a notebook, you can use the ! operator with pip to install the TA-Lib package.

Try this :

!pip install TA-Lib

As suggested by @DarknessPlusPlus, you can also use the magic command % :

%pip install TA-Lib

This answer by @jakevdp explains the difference between the two commands.

# Edit :

If you still can't import the modules, run this in a Google Colab cell :

!curl -L http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz -O && tar xzvf ta-lib-0.4.0-src.tar.gz
!cd ta-lib && ./configure --prefix=/usr && make && make install && cd - && pip install ta-lib

# Result :

enter image description here

But before that, make sure to uninstall any talib package with :

%pip uninstall TA-lib talib-binary

Upvotes: 4

Related Questions