If you’ve been interested in implementing trading bots in Python, you might have heard about TA-Lib. This technical analysis library stands out due to its maturity, popularity, and an extensive list of indicators. Moreover, its backend is programmed in C ( a low-level programming language), and thus it delivers faster execution times compared to other alternatives available.
Despite its apparent advantages, it also has some drawbacks, mainly its cumbersome installation process. It is because of this that I regularly get asked about the installation process and the numerous errors that arise. This article is just the public version of what I always reply to privately by email. I even recorded a video you can watch if you prefer that medium over text (I certainly do so!).
Before getting started, it’s worth mentioning that I recommend using BacktestXL if you’re not a proficient Python programmer. BacktestXL is a backtesting engine that works natively in Microsoft Excel, and its free plan allows users to fetch historical stock prices without a single line of code. Disclaimer: we’re the developers, but it really is the software we use for our personal research!
TA-Lib for Python Installation
In order to install TA-Lib, we need to know which Python version we have installed on our local environment and check whether we have a 64bit or 32bit operating system. Let’s go ahead and do that!
Checking local environment specifications
In order to check the Python version installed on your computer, go ahead and open a command prompt (terminal) and type the following command:
In my case, I’m currently using Python 3.8.8
Additionally, we have to know the system type of our processor. If you’re using Windows, you can right-click the Desktop icon and select “Properties.”
You will not be able to see a detailed list of your computers’ specifications, so go ahead and check whether you have an x64 or x86 system. In most cases, this will just be a formality since most computers today have x64-based processors.
Downloading the ta-lib binary and installing it
Now that we know all the necessary computer specs refer to the following link and look for “ta-lib.” As you will see, there are quite a few different versions, and installing precisely the one you need is essential.
As I reference, I’m running Python 3.8.8 on a 64-bit processor, so I choose “TA_Lib‑0.4.24‑cp38‑cp38‑win_amd64.whl”. More probable than not, you will have to download another file.
After downloading the file, paste it into your users’ root folder (“C:\Users\<YOUR_USERNAME>”.
Open another terminal and install the file using the following command (modify it according to your respective filename and username):
pip install TA_Lib‑0.4.24‑cp38‑cp38‑win_amd64.whl
If you were able to do it correctly, you should now be seeing something along the following lines:
Having done so, you can now go ahead and install the ta-lib python library by typing in the following command on the same terminal:
pip install ta-lib
In my case, I already had the library installed, but you should be prompted a message stating that the library was successfully installed.
You can now fire up a Jupyter Notebook or a blank python file and try to import the library. If you’re luckier than me, you’ll have no further issues and will be able to start using the library!
Solving TA-Lib Installation Errors
If you’re still facing issues, it is very probable that they are caused due to a compatibility issue between Talib and NumPy. If you followed the previous steps of the tutorial, you are probably seeing the following error when trying to import the library:
This error is not only annoying but also not very insightful. After going back and forth through many potential solutions, I (and most of my colleagues) managed to solve this issue by reinstalling Numpy. This is pretty straightforward:
pip uninstall numpy pip install numpy
Et voila! You should now be able to use one of the most mature and fastest technical analysis libraries available for Python.
Frequently Asked Questions
What is TA-Lib?
TA-Lib, short for “technical analysis library,” is the most popular open-source project for calculating technical analysis indicators. Being written in a low-level programming language, it is superior in terms of execution speed when compared to other alternatives. Due to its popularity, it currently has wrappers for Java, C+, Perl, C, and most importantly, Python. Started back in 1999, the project is by far one of the most mature and thoroughly tested of its kind.
Best alternative to TA-Lib
If you want to avoid going through the hassle of installing Talib on your computer or want to make your script more “shareable” to other users, you should choose pandas_ta. This library is as easy to install as most python libraries (pip install pandas_ta), offers a wide array of technical indicators, and is being actively maintained by lots of contributors.
A nice feature of pandas_ta is that it will leverage Talib if installed in your local environment. Consequently, you can easily share your code with your peers while also benefiting from having a blazingly fast implementation in the backend if you install Talib.
Is TA-Lib faster than other technical analysis libraries?
In contrast to other alternatives, TA-Lib is implemented in C, a low-level programming language that is able to perform calculations much faster than native Python. Thus, TA-Lib is faster than all other alternatives available in Python.
Having said that, other libraries allow to switch between using TA-Lib or their own implementation in the backend, and such is the case of pandas-ta. This library brings the best of both worlds together since it is easy to install (a simple pip install pandas_ta will do the trick), and allows to leverage of Talib’s speed of execution if necessary. Of course, to use ta-lib as the backend, you will have to go through the hassle of installing it.