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.

How to Install Ta-Lib in Python – Part IV

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 hosted with ❤ by GitHub

wget -O "" \
  && /bin/bash -b \
  && rm \
  && ./anaconda3/bin/conda init \
  && source ~/.bashrc \
  && conda create -n quantra python=3.6.8 -y \
  && conda activate quantra 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 \
  && 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 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 hosted with ❤ by GitHub

Launch Python

import talib as ta
import yfinance as yf
aapl ='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()) 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:

Disclosure: Interactive Brokers

Information posted on IBKR Traders’ Insight that is provided by third-parties and not by Interactive Brokers does NOT constitute a recommendation by Interactive Brokers that you should contract for the services of that third party. Third-party participants who contribute to IBKR Traders’ Insight 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 permission from QuantInsti. The views expressed in this material are solely those of the author and/or QuantInsti and IBKR 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 sell or the solicitation of an offer to buy any security. To the extent that this material discusses general market activity, industry or sector trends or other broad based economic or political conditions, it should not be construed as research or investment advice. To the extent that it includes references to specific securities, commodities, currencies, or other instruments, those references do not constitute a recommendation to buy, sell or hold such security. 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.

In accordance with EU regulation: The statements in this document shall not be considered as an objective or independent explanation of the matters. Please note that this document (a) has not been prepared in accordance with legal requirements designed to promote the independence of investment research, and (b) is not subject to any prohibition on dealing ahead of the dissemination or publication of investment research.

Any trading symbols displayed are for illustrative purposes only and are not intended to portray recommendations.

trading top