Select Page

TA-Lib is a very popular Technical Analysis library among Python developers who develop their trading strategies from scratch. The only downside is when you try to add it in your Python application the first time, you most likely will get errors.

I received messages from my readers thanking me on how my blog post Installing TA-Lib Wheel (WHL file) in Windows had helped them solve this problem. For MacOS users, this is also an issue but the solution is so much easier than that of Windows.

The error logs

Below is what you may see in your logs after installing requirements.txt with TA-Lib on it or directly installing TA-Lib from the Terminal.

pip install -r .\requirements.txt

pip install TA-lib

Building wheels for collected packages: TA-Lib, peewee
  Building wheel for TA-Lib (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Building wheel for TA-Lib (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [21 lines of output]
      <string>:77: UserWarning: Cannot find ta-lib library, installation may fail.
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.macosx-10.9-universal2-cpython-311
      creating build/lib.macosx-10.9-universal2-cpython-311/talib
      copying talib/abstract.py -> build/lib.macosx-10.9-universal2-cpython-311/talib
      copying talib/deprecated.py -> build/lib.macosx-10.9-universal2-cpython-311/talib
      copying talib/__init__.py -> build/lib.macosx-10.9-universal2-cpython-311/talib
      copying talib/stream.py -> build/lib.macosx-10.9-universal2-cpython-311/talib
      running build_ext
      building 'talib._ta_lib' extension
      creating build/temp.macosx-10.9-universal2-cpython-311
      creating build/temp.macosx-10.9-universal2-cpython-311/talib
      clang -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch arm64 -arch x86_64 -g -I/usr/include -I/usr/local/include -I/opt/include -I/opt/local/include -I/opt/homebrew/include -I/opt/homebrew/opt/ta-lib/include -I/private/var/folders/k3/b2rf6p9j7d3czjsj_p4t_8fr0000gr/T/pip-build-env-jcs_kqlv/normal/lib/python3.11/site-packages/numpy/core/include -I/Users/TechieJackie/PycharmProjects/stockstrading/venv/include -I/Library/Frameworks/Python.framework/Versions/3.11/include/python3.11 -c talib/_ta_lib.c -o build/temp.macosx-10.9-universal2-cpython-311/talib/_ta_lib.o
      talib/_ta_lib.c:1082:10: fatal error: 'ta-lib/ta_defs.h' file not found
      #include "ta-lib/ta_defs.h"
               ^~~~~~~~~~~~~~~~~~
      1 error generated.
      error: command '/usr/bin/clang' failed with exit code 1
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for TA-Lib
  Building wheel for peewee (pyproject.toml) ... done
  Created wheel for peewee: filename=peewee-3.16.3-cp311-cp311-macosx_10_9_universal2.whl size=418815 sha256=979aeb4f1871bef54d5b521d68e51e5bde27cf5ffa32b3f0b5b0500d9c795e85
  Stored in directory: /Users/TechieJackie/Library/Caches/pip/wheels/9a/57/07/03fab5c326bdcb4a5d12fce1003c44ee9b7c55a97e579dcbcb
Successfully built peewee
Failed to build TA-Lib
ERROR: Could not build wheels for TA-Lib, which is required to install pyproject.toml-based projects

The solution:

Step 1. Run brew install ta-lib on the Terminal.

(venv) TJB@TechieJackie-MacBook-Pro stockstrading % brew install ta-lib

Step 2. Run again your pip3 install command on the Terminal.

pip install -r .\requirements.txt

pip install TA-lib

Collecting TA-lib
  Downloading TA-Lib-0.4.28.tar.gz (357 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 357.1/357.1 kB 6.6 MB/s eta 0:00:00
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: numpy in ./venv/lib/python3.11/site-packages (from TA-lib) (1.26.0)
Building wheels for collected packages: TA-lib
  Building wheel for TA-lib (pyproject.toml) ... done
  Created wheel for TA-lib: filename=TA_Lib-0.4.28-cp311-cp311-macosx_10_9_universal2.whl size=842597 sha256=fad2d64640494d0af99f3f24a39f61830dbd3e009eac0a71b5c4902b6aec7eae
  Stored in directory: /Users/TechieJackie/Library/Caches/pip/wheels/77/bf/7e/42bf2d8e023e71f7d513fd51694ab5acadd86b40e6f50f5744
Successfully built TA-lib
Installing collected packages: TA-lib
Successfully installed TA-lib-0.4.28

The library will be installed successfully on MacOS X machines. Viola! You may now use TA-lib in your Python apps.