How to install TA-Lib in Google Colab?
Asked Answered
H

5

25

I'm trying to install the TA-Lib package in Google Colab but without success.

I tried this guide and also Installing TA-Lib on python x64.

I get this error:

import platform
print (platform.architecture())

import sys
print(sys.version)

!pip install C:/ta-lib/TA_Lib-0.4.17-cp36-cp36m-win_amd64.whl

#########
('64bit', '')
3.6.3 (default, Oct  3 2017, 21:45:48) 
[GCC 7.2.0]
 Requirement 'C:/ta-lib/TA_Lib-0.4.17-cp36-cp36m-win_amd64.whl' looks like a 
  filename, but the file does not exist
  TA_Lib-0.4.17-cp36-cp36m-win_amd64.whl is not a supported wheel on this 
  platform.
Humanize answered 4/4, 2018 at 10:11 Comment(2)
Colab is run on Ubuntu Linux, not Windows.Slimy
Good to know, Thanks for the comment. Do you know how to install the package on colab? or any guide?Humanize
S
87

Have you tried following instructions from here?

https://github.com/mrjbq7/ta-lib

And change any sudo apt-get to just !apt. Any cd to %cd

Update: try this

!wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz
!tar -xzvf ta-lib-0.4.0-src.tar.gz
%cd ta-lib
!./configure --prefix=/usr
!make
!make install
!pip install Ta-Lib
import talib

Update(may 2020): for binary install (no compile)

url = 'https://launchpad.net/~mario-mariomedina/+archive/ubuntu/talib/+files'
ext = '0.4.0-oneiric1_amd64.deb -qO'
!wget $url/libta-lib0_$ext libta.deb
!wget $url/ta-lib0-dev_$ext ta.deb
!dpkg -i libta.deb ta.deb
!pip install ta-lib
import talib

Update(may 2021): even faster

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
import talib

Update (dec 2021): from @roborative, this is easiest to remember and take 3.8s (above is 1.2s)

!pip install talib-binary

Update (mar 2023): Colab is now Python 3.9, talib-binary is not updated yet, so revert to conda extraction

url = 'https://anaconda.org/conda-forge/libta-lib/0.4.0/download/linux-64/libta-lib-0.4.0-h166bdaf_1.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-py39hd257fcd_4.tar.bz2'
!curl -L $url | tar xj -C /usr/local/lib/python3.9/dist-packages/ lib/python3.9/site-packages/talib --strip-components=3
import talib

Update (apr 2023): Colab is now Python 3.10

url = 'https://anaconda.org/conda-forge/libta-lib/0.4.0/download/linux-64/libta-lib-0.4.0-h166bdaf_1.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-py310hde88566_4.tar.bz2'
!curl -L $url | tar xj -C /usr/local/lib/python3.10/dist-packages/ lib/python3.10/site-packages/talib --strip-components=3
import talib
Slimy answered 4/4, 2018 at 21:9 Comment(4)
Faster still is the approach suggested in this post of using pip to install talib-binary.Romilly
!pip install talib-binary doesn't work anymore.Trust
@Trust I update the answer for Python 3.9 nowSlimy
yesterday they updated to python 3.10 and it does not work anymoreBrown
D
4

The 2022 update provided in korakot's answer works on Google Colab:

!pip install talib-binary

Then simply import the library:

import talib as tb
Destalinization answered 29/1, 2022 at 12:21 Comment(0)
W
0

!pip install TA-lib does not work so downloading `.tar.gz' will work

First step: download

1. using os package

https://colab.research.google.com/drive/1xGx21E4oafx4WQbOCSPtQsxkD-ruMdK-#scrollTo=Yy9KWlGas0Me

!wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz 
!tar xvzf ta-lib-0.4.0-src.tar.gz
import os
os.chdir('ta-lib') # Can't use !cd in co-lab
!./configure --prefix=/usr
!make
!make install
os.chdir('../')
!pip install TA-Lib

2. Using the %%bash command .

!wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz
!tar -xvf ta-lib-0.4.0-src.tar.gz
%%bash
cd ta-lib
./configure --prefix=/usr
make
sudo make install
sudo apt upgrade
#!pip install TA-Lib
!pip install ta-lib

Last step: import talib

If you are using Ubuntu and Jupyter then this answer is helpful Unable to install TA-Lib on Ubuntu

Wellbalanced answered 1/5, 2019 at 15:32 Comment(0)
C
0

The way it worked for me from a container and running jupyter notebook is the following:
import os,sys
Clean everything if previosuly. !rm -rf ta-lib*
Download the package
!wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz
Unpack the tar.
!tar xvf ta-lib-0.4.0-src.tar.gz
!pwd
!ls -l
Move to the unpacked and run the files.
!cd /home/$USER/work/ta-lib/ && ./configure --prefix=/usr
!cd /home/$USER/work/ta-lib/ && make
!cd /home/$USER/work/ta-lib/ && sudo make install
Install now the package
!pip install --user Ta-Lib
Import and tadaaa!
import talib

Carpous answered 2/9, 2020 at 9:54 Comment(1)
Hi user789313, I did the same as you wrote. But as I run the 'import talib' I got error as follow: ModuleNotFoundError Traceback (most recent call last) <ipython-input-6-4aaeb47f62d3> in <module> 6 # !cd {nb_path}/ta-lib && sudo make install 7 # !pip install --user Ta-Lib ----> 8 import talib ModuleNotFoundError: No module named 'talib'Andino
V
0

To execute talib please use below code. I have executed this successfully in Google Colab.

!wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz 
!ls
!tar xvzf ta-lib-0.4.0-src.tar.gz
!ls
import os

os.chdir('/lib/Ta-lib') #This path should exist in your colab folder, copy file path from there after making new folder

!./configure --prefix=/usr

!make

!make install

os.chdir('../')

!ls

!pip install TA-Lib

import talib as ta
Victim answered 19/4 at 22:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.