Reputation: 8791
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?
Upvotes: 13
Views: 20405
Reputation: 148
I was able to install Ta-lib on a raspberry pi 4 with Ubuntu using the following commands:
wget https://github.com/ta-lib/ta-lib/releases/download/v0.6.4/ta-lib_0.6.4_arm64.deb
sudo dpkg -i ta-lib_0.6.4_arm64.deb
pip install TA-Lib
Upvotes: 0
Reputation: 3379
I created this python file called install_talib.py
. Just ran the file and ta-lib was installed. It was a perfect solution in my case!.
import subprocess
import os
import sys
subprocess.run(["wget", "http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz"])
subprocess.run(["tar", "-xzf", "ta-lib-0.4.0-src.tar.gz"])
os.chdir("ta-lib")
subprocess.run(["./configure", "--prefix=/usr"])
subprocess.run(["make"])
subprocess.run(["sudo", "make", "install"])
subprocess.run([sys.executable, "-m", "pip", "install", "ta-lib"])
subprocess.run(['pip', 'install', 'numpy==1.26.4'])
To run install_talib.py
:
sudo apt update
python install_talib.py
Upvotes: 1
Reputation: 515
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...
build-essential
and python-dev
(python3-dev
, python3.10-dev
).wget
.make
and make install
.make
TA-Lib and make install
it.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.
All in all, I hope this helps; for me, it made a once frustrating and volatile process easy.
Upvotes: 6
Reputation: 2959
I am able to load in python3.
Steps:
download from http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz
untar tar -xvf ta-lib-0.4.0-src.tar.gz
cd /../ta-lib
./configure --prefix=/usr
make
sudo make install
sudo apt upgrade
pip install ta-lib
or pip install TA-Lib
Check import talib
Upvotes: 36
Reputation: 179
Seem like other people had this problem.
To quote the accepted answer:
Seems that your PiP can't access Setuptools as per the "import setuptools" in the error. Try the below first then try running your pip install again.
> sudo pip install -U setuptools
Or if it doesn't work to quote his comment:
Try this 'sudo -H pip install TA-Lib'
As Filipe Ferminiano said in comment if this still doesn't fix it then you can try what is said on this link .
To quote the accepted answer once again:
Your sudo is not getting the right python. This is a known behaviour of sudo in Ubuntu. See this question for more info. You need to make sure that sudo calls the right python, either by using the full path:
sudo /usr/local/epd/bin/python setup.py install
or by doing the following (in bash):
alias sudo='sudo env PATH=$PATH'
sudo python setup.py install
Here is the question he's talking about
Please give credit to the one of the accepted answer if it fix your problem.
Upvotes: 3