Close Navigation
Learn more about IBKR accounts
How to Install Ta-Lib in Python – Part IV

How to Install Ta-Lib in Python – Part IV

Posted August 24, 2021
Ishan Shah, Rekhit Pachanekar and Gaurav Singh
QuantInsti

Ishan Shah, Rekhit Pachanekar and Gaurav Singh demonstrate how to install Ta-Lib across platforms using Anaconda prompt in Part I, and showcase how to install it on Windows PC in Part II and on MacOS in Part III.

The Ta-lib installation in Linux can be a bit tricky. The libraries necessary for the Ta-lib installation should be installed first before you install the Python wrapper.

But don’t worry! We have provided comprehensive steps on how to install the Ta-lib library in your Linux system.

Step 0: Install Anaconda in your Linux system. You can follow the documentation or execute the commands as shared below.

The following command installs the Anaconda software and creates an environment named ‘quantra’. You can use this environment for your Quantra related coding projects!

  • Install the prerequisites
  • Install Anaconda on your system
sudo apt-get -y install gcc build-essential
install_anaconda.sh hosted with ❤ by GitHub

wget -O inst_conda.sh "https://repo.anaconda.com/archive/Anaconda3-2020.11-Linux-x86_64.sh" \
  && /bin/bash inst_conda.sh -b \
  && rm inst_conda.sh \
  && ./anaconda3/bin/conda init \
  && source ~/.bashrc \
  && conda create -n quantra python=3.6.8 -y \
  && conda activate quantra
pre_requisites.sh hosted with ❤ by GitHub

Install Anaconda and create a new environment

Step 1: Install the Ta-lib dependencies and Python wrapper by executing the following command.

wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz \
  && sudo tar -xzf ta-lib-0.4.0-src.tar.gz \
  && sudo rm ta-lib-0.4.0-src.tar.gz \
  && cd ta-lib/ \
  && sudo ./configure --prefix=/usr \
  && sudo make \
  && sudo make install \
  && cd ~ \
  && sudo rm -rf ta-lib/ \
  && pip install ta-lib
install_talib.sh hosted with ❤ by GitHub

Install the Ta-lib dependencies and Python wrapper

This will take a couple of minutes and install all the libraries necessary for using Ta-lib.

Ta-lib installation complete

Step 2: Test the Ta-lib installation by executing a sample script. We take some data and try to find the moving average using the Ta-lib libraries.

  • Install yfinance library if you do not have it already
  • Run Python in the terminal
  • Paste the following code lines to check if Ta-lib is working properly or not.
  • You should see a Simple MA and EMA column similar to the screenshot below.
pip install yfinance==0.1.44
install_yfinance.sh hosted with ❤ by GitHub

Launch Python

import talib as ta
import yfinance as yf
aapl = yf.download('AAPL', '2019-1-1','2019-12-27')
aapl['Simple MA'] = ta.SMA(aapl['Close'],14)
aapl['EMA'] = ta.EMA(aapl['Close'], timeperiod = 14)
print(aapl.tail())
sample_script.py hosted with ❤ by GitHub

Ta-lib output for the sample script

The Ta-lib library is now installed in the ‘quantra’ environment! To know how to activate and switch environments, please refer to the Conda resource.

Awesome! We have now been successful in installing Python Ta-Lib on Windows, MacOS and Linux. But can we really stop here?

In the next section, we try a simple code using the Ta-Lib library.

In the next installments, the authors will explore technical indicators using Python Ta-Lib.

Visit QuantInsti for additional insight on this topic:
https://blog.quantinsti.com/install-ta-lib-python/

Disclosure: Interactive Brokers

Information posted on IBKR Campus that is provided by third-parties does NOT constitute a recommendation that you should contract for the services of that third party. Third-party participants who contribute to IBKR Campus are independent of Interactive Brokers and Interactive Brokers does not make any representations or warranties concerning the services offered, their past or future performance, or the accuracy of the information provided by the third party. Past performance is no guarantee of future results.

This material is from QuantInsti and is being posted with its permission. The views expressed in this material are solely those of the author and/or QuantInsti and Interactive Brokers is not endorsing or recommending any investment or trading discussed in the material. This material is not and should not be construed as an offer to buy or sell any security. It should not be construed as research or investment advice or a recommendation to buy, sell or hold any security or commodity. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.

IBKR Campus Newsletters

This website uses cookies to collect usage information in order to offer a better browsing experience. By browsing this site or by clicking on the "ACCEPT COOKIES" button you accept our Cookie Policy.