Unable to install TA-Lib on Ubuntu

Viewed 15054

I'm trying to install Python Ta-Lib in Ubuntu,but when I run:

pip install TA-Lib

I get this error:

Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-YfCSFn/TA-Lib/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-swmI7D-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-YfCSFn/TA-Lib/

I already installed:

sudo apt-get install python3-dev

and installed Ta-lib

How can I fix this?

3 Answers

This has always been a tricky one, but I had made a script that has served me loyally in several Ubuntu physical, VM, and server instances (including GitHub Actions).

It's a little long but it's comprehensive and has worked in every Ubuntu instance I've needed it for. It includes a few precautionary steps that have previously caused errors.

sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y
sudo apt install wget -y
sudo add-apt-repository ppa:deadsnakes/ppa -y
sudo apt-get install build-essential -y
sudo apt install python3.10-dev -y
sudo apt-get install python3-dev -y

wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz
tar -xzf ta-lib-0.4.0-src.tar.gz
cd ta-lib

wget 'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD' -O './config.guess'
wget 'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD' -O './config.sub'
./configure --prefix=/usr
make
sudo make install

sudo rm -rf ta-lib
sudo rm -rf ta-lib-0.4.0-src.tar.gz

pip install ta-lib

It consists of many steps...

  1. Update built-in packages using apt.
  2. Add the deadsnakes repo.
  3. Install build-essential and python-dev (python3-dev, python3.10-dev).
  4. Download the TA-Lib tarball with wget.
  5. Download the updated make recognizer files to prevent common issues with make and make install.
  6. make TA-Lib and make install it.
  7. Clean up the mess.
  8. Install with pip to make sure everything worked out. (pip will install the latest version of TA-Lib, 0.4.24, even though we can only download the source for 0.4.0. This works fine.)

Because I use this frequently, I turned it into a gist, for the purpose of accessing the script directly with curl.

Just grab a raw link from the Gist page and use it like below.

curl https://gist.githubusercontent.com/preritdas/bunchofrandomstuffhere/install-talib-ubuntu.sh | sudo bash

Make sure you're sudo activated before running the command to prevent issues. It will run all the above commands as a script and install TA-Lib in about 4-5 minutes (average, in my experience).

Here's a shell recording of this working on a fresh server instance of Ubuntu 22.04.

asciicast

All in all, I hope this helps; for me, it made a once frustrating and volatile process easy.

Related