Trouble Installing TA-Lib in Python 3.7

Question:

I am trying to install TA-Lib for Python 3.7. I’ve already read through a number of solutions, but have come to a point I can’t figure out. Here is the message I get from pip:

Collecting ta-lib
  Using cached https://files.pythonhosted.org/packages/90/05/d4c6a778d7a7de0be366bc4a850b4ffaeac2abad927f95fa8ba6f355a082/TA-Lib-0.4.17.tar.gz
Requirement already satisfied: numpy in c:python37_64libsite-packages (from ta-lib) (1.15.4)
Installing collected packages: ta-lib
  Running setup.py install for ta-lib: started
Command "c:python37_64python.exe -u -c "import setuptools, tokenize;__file__='C:\Users\Todd\AppData\Local\Temp\pip-install-0c2__0gf\ta-lib\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('rn', 'n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:UsersToddAppDataLocalTemppip-record-3dpfancainstall-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:UsersToddAppDataLocalTemppip-install-0c2__0gfta-lib
    Running setup.py install for ta-lib: finished with status 'error'
    Complete output from command c:python37_64python.exe -u -c "import setuptools, tokenize;__file__='C:\Users\Todd\AppData\Local\Temp\pip-install-0c2__0gf\ta-lib\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('rn', 'n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:UsersToddAppDataLocalTemppip-record-3dpfancainstall-record.txt --single-version-externally-managed --compile:
    C:UsersToddAppDataLocalTemppip-install-0c2__0gfta-libsetup.py:79: UserWarning: Cannot find ta-lib library, installation may fail.
      warnings.warn('Cannot find ta-lib library, installation may fail.')
    running install
    running build
    running build_py
    creating build
    creating buildlib.win-amd64-3.7
    creating buildlib.win-amd64-3.7talib
    copying talibabstract.py -> buildlib.win-amd64-3.7talib
    copying talibdeprecated.py -> buildlib.win-amd64-3.7talib
    copying talibstream.py -> buildlib.win-amd64-3.7talib
    copying talibtest_abstract.py -> buildlib.win-amd64-3.7talib
    copying talibtest_data.py -> buildlib.win-amd64-3.7talib
    copying talibtest_func.py -> buildlib.win-amd64-3.7talib
    copying talibtest_pandas.py -> buildlib.win-amd64-3.7talib
    copying talibtest_stream.py -> buildlib.win-amd64-3.7talib
    copying talib__init__.py -> buildlib.win-amd64-3.7talib
    running build_ext
    building 'talib._ta_lib' extension
    creating buildtemp.win-amd64-3.7
    creating buildtemp.win-amd64-3.7Release
    creating buildtemp.win-amd64-3.7Releasetalib
    C:Program Files (x86)Microsoft Visual Studio2017BuildToolsVCToolsMSVC14.16.27023binHostX86x64cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Ic:python37_64libsite-packagesnumpycoreinclude -Ic:ta-libcinclude -Ic:python37_64include -Ic:python37_64include "-IC:Program Files (x86)Microsoft Visual Studio2017BuildToolsVCToolsMSVC14.16.27023include" "-IC:Program Files (x86)Windows Kits10include10.0.17763.0ucrt" "-IC:Program Files (x86)Windows Kits10include10.0.17763.0shared" "-IC:Program Files (x86)Windows Kits10include10.0.17763.0um" "-IC:Program Files (x86)Windows Kits10include10.0.17763.0winrt" "-IC:Program Files (x86)Windows Kits10include10.0.17763.0cppwinrt" /Tctalib/_ta_lib.c /Fobuildtemp.win-amd64-3.7Releasetalib/_ta_lib.obj
    _ta_lib.c
    talib/_ta_lib.c(524): fatal error C1083: Cannot open include file: 'ta_libc.h': No such file or directory
    error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe' failed with exit status 2

    ----------------------------------------
FINISHED

Thanks.

Asked By: Todd Burus

||

Answers:

i would suggest installing using the wheel from here. Recently i ran across the same problems while trying to upgrade the library which is again another thing you wouldn’t want to do.
Hope this helps. Good luck.

Answered By: user3529864

Here is what works for me…

Download TA_Lib-0.4.10-cp27-cp27m-win_amd64.whl from here
And use command pip install TA_Lib-0.4.10-cp27-cp27m-win_amd64.whl

I was using Conda4 with python 3.6 64 bit version.

Another way also you can try

To install Ta-Lib with Python 3.6+, Windows 64 bit use this pip install -i https://pypi.anaconda.org/masdeseiscaracteres/simple ta-lib

Answered By: mlbishnoi

The root cause of the error is probably because you haven’t installed actual TA-Lib library which is written in C. Note that the python lib is just a wrapper on top of the actual library. So in order to have python wrapper successfully installed, you’ll need to install its prerequisite (the actual TA-Lib).

See https://github.com/mrjbq7/ta-lib#dependencies for more details.

From above reference (for ease of access) :

Installing actual TA-Lib (prerequisite for python wrapper) :

Windows

  1. Download ta-lib-0.4.0-msvc.zip and unzip to C:ta-lib

  2. Move the Unzipped Folder ta-lib to C:

  3. Download and Install Visual Studio Community 2015 if already not installed (Remember to Select [Visual C++] Feature)

  4. open x64 Native Tools Command Prompt

  5. navigate to C:ta-libcmakecdrwin32msvc

  6. type nmake (this command builds the library)

Linux

$ tar -xzf ta-lib-0.4.0-src.tar.gz
$ cd ta-lib/
$ ./configure --prefix=/usr
$ make
$ sudo make install

Mac OS X

$ brew install ta-lib

If you are using a M1 laptop and Homebrew, then you can set these before installing:

export TA_INCLUDE_PATH="$(brew --prefix ta-lib)/include"
export TA_LIBRARY_PATH="$(brew --prefix ta-lib)/lib"

Hint : It seems, by default, the setup.py reads actual library files from C:ta-lib (in Windows) and /usr (in Linux). so if you move the downloaded zip file to another location and extract it there (for Windows) or set ./configure --prefix to any location other than /usr (for Linux), then you would have to set TA_LIBRARY_PATH and TA_INCLUDE_PATH environment variables to your desired locations.

If you installed the underlying TA-Lib library with a custom prefix (e.g., with ./configure –prefix=$PREFIX), then when you go to install this python wrapper you can specify additional search paths to find the library and include files for the underlying TA-Lib library using the TA_LIBRARY_PATH and TA_INCLUDE_PATH environment variables:

$ export TA_LIBRARY_PATH=$PREFIX/lib
$ export TA_INCLUDE_PATH=$PREFIX/include
$ python setup.py install # or pip install ta-lib
Answered By: Code_Worm

The documentation of Ta-lib package here is well clear:

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

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

And as it was clearly mentionned! this python ta-lib library! Is a wrapper for the TaLib library at https://ta-lib.org/

This is a Python wrapper for TA-LIB based on Cython instead of SWIG

To know the ta-lib.org library is a library created in c lang! You can check here

And multiple binding and interfaces are made for different languages! Just as mentionned in the official website!

The python library is a binding for python that use cython! Which make it more efficient then SWIG!

Know that I’ll insist on using pip! (it works all well and it’s convenient)

For the installation to go well! You’ll need to go in two steps! You need to install TaLib native library binaries first! Then install the python lib with pip (again with pip)! And this order is necessary! You can’t go for installing the python binding before the first installation finish!

All that said!

Installation

Step 1: Installing Talib native binary

Installing the Ta-lib software (Or native library binary)! Is a must! And need to be done first!

Follow the instructions here:

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

The instructions are too clear and detailed!

(Linux users you need to execute the command with the right privelege (hince using sudo))

And last thing! You can check @Code_Worm answer in this thread here He explained many points highly well aboutt the instruction above !

I’ll pin point too his hint:

Hint : It seems, by default, the setup.py reads actual library files from C:ta-lib (in Windows) and /usr (in Linux). so if you move the downloaded zip file to another location and extract it there (for Windows) or set ./configure –prefix to any location other than /usr (for Linux), then you would have to set TA_LIBRARY_PATH and TA_INCLUDE_PATH environment variables to your desired locations.

Check the section bellow this hint!

You can check the trouble shooting section here

Step 2: Installing the python library using pip

Don’t proceed with this step until the first step is successfully finished and done with!

Again the pip package and pip works well! And so no need to use some whl file from any other website and src! I’ll show you how!

pip install TA-Lib

However here there is many things to say!

First you need to use python 3

So you may use pip3 instead of pip! If pip is resolving to the python2 version (which is common in linux installations)!

pip3 install TA-Lib

Now you may fall in this problem and error!

unescape = getattr(html, 'unescape', html_parser.HTMLParser().unescape)
AttributeError: 'HTMLParser' object has no attribute 'unescape'

IF such is the case! That’s a problem that can come with python 3.9! (if you are using 3.8 you may not encounter that at all)!

The solution and fix is simple! We have just to make an upgrade to some packages! You can follow the instructions from the answer here:

https://stackoverflow.com/a/65640477/7668448

After some trial and error I upgraded, pip, distlib and setuptools and it solved it. Not sure which of those is causing it. (On the last two I found issues 1 2 of other sites)
It is caused by removing unescape from HTMLParser in python3.9, which seems to break setuptools.

pip3 install --upgrade setuptools

If it does not work, try also:

pip3 install --upgrade pip
pip3 install --upgrade distlib

That’s it all! If the first step (step 1: Installing TaLib native binaries) is well done and finished! Then running pip3 install TA-Lib will works well this time!

For Linux users! If you run it with sudo! And it failed! Don’t use sudo! You should not!

For linux users you may need to install python headers

sudo apt-get install python3-dev

You can try it only if it didn’t works! In most linux distro! You’ll be ok by default!

Last (Trouble shooting doc section)

If needed Check the trouble shooting section here

Answered By: Mohamed Allal

If you didn’t installed first TA-lib native library (as mentioned here and installed python ta-lib first it helps to re-install TA-lib using: pip install –upgrade –force-reinstall TA-lib

Answered By: arg
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.