Install ta-lib in python 3.7

joel
2 min readAug 1, 2019

--

The scenario is I am trying to install ta-lib in anaconda environment. Tried the following commands but all failed.

$ conda install -c quantopian ta-lib$ conda install -c masdeseiscaracteres ta-lib$ conda install -c developer ta-lib

Tried many pip install commands but still failed. All those tries above are failed because my python version is 3.7. Got a lot of notices or warning messages said python version should be < v3.6.

But finally by reading ta-lib README.md file, I tried the following way, it works.

Okay, let’s start.

  1. Download [ta-lib-0.4.0-src.tar.gz]
# before we start installing, we need to make it sure that gcc is
# installed in your linux system.
# Please run the following command:
$ sudo apt install build-essential
# now we start compile ta-lib library$ wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz
$ tar xvf ta-lib-0.4.0-src.tar.gz
$ cd ta-lib
$ ./configure --prefix=/usr
$ make
$ sudo make install

2. Download TA-Lib-0.4.17.tar.gz

$ wget https://files.pythonhosted.org/packages/90/05/d4c6a778d7a7de0be366bc4a850b4ffaeac2abad927f95fa8ba6f355a082/TA-Lib-0.4.17.tar.gz
$ tar xvf TA-Lib-0.4.17.tar.gz
$ cd TA-Lib-0.4.17
$ python setup.py install

3. If we get an error message: “ImportError: libta_lib.so.0: cannot open shared object file: No such file or directory”
Then run the following command:

$ sudo find / -name libta_lib.so*
# If the files are located in /usr/lib,
# then we run the following command:
$ sudo echo “include /usr/lib” >> /etc/ld.so.conf
$ sudo ldconfig

4. Test it, it should work.

$ python -c "import talib; print(talib.__version__)"

PS: this is a Dockerfile for creating a talib image.

FROM python:3.7WORKDIR /tmpRUN pip install numpy
RUN pip install pandas
RUN pip install sqlalchemy
# TA-Lib
RUN wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz && \
tar -xvzf ta-lib-0.4.0-src.tar.gz && \
cd ta-lib/ && \
./configure — prefix=/usr && \
make && \
make install && \
cd .. && \
wget https://files.pythonhosted.org/packages/90/05/d4c6a778d7a7de0be366bc4a850b4ffaeac2abad927f95fa8ba6f355a082/TA-Lib-0.4.17.tar.gz && \
tar xvf TA-Lib-0.4.17.tar.gz && \
cd TA-Lib-0.4.17 && \
python setup.py install && \
cd ..
RUN rm -R ta-lib ta-lib-0.4.0-src.tar.gz TA-Lib-0.4.17 TA-Lib-0.4.17.tar.gz

--

--

Responses (1)