ta-lib-python icon indicating copy to clipboard operation
ta-lib-python copied to clipboard

Please teach me about the compatibility between talib and numpy.

Open Ktachi87 opened this issue 3 years ago • 2 comments

Sorry for the layman's question. Can someone please advise me on this?

I tried to analyze stock prices, and I referred to the following site, but I cannot use TA-lib. https://www.youtube.com/watch?v=6R6-BCFd7zM

I checked the GITHUB logs and found that it is most likely a problem with some software ver, but I couldn't find an answer in the end. I would like to use TA-lib on Docker in the following environment, but it does not work.

python: lastest(docker image --> TAG) numpy: 1.16.2

Followings are the codes I used and error codes.

code[jupyter-lab]

import pandas as pd import numpy as np import talib as ta from pandas_datareader import data import matplotlib.pyplot as plt %matplotlib inline import warmimgs warnings.simplefilter('ignore')

error code[jupyter-lab]

ValueError Traceback (most recent call last) in 1 import pandas as pd 2 import numpy as np ----> 3 import talib as ta 4 from pandas_datareader import data 5 import matplotlib.pyplot as plt

~/anaconda3/lib/python3.7/site-packages/talib/init.py in 91 92 ---> 93 from ._ta_lib import ( 94 _ta_initialize, _ta_shutdown, MA_Type, ta_version, 95 _ta_set_unstable_period as set_unstable_period,

talib/_ta_lib.pyx in init talib._ta_lib()

ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject

docker file:

FROM ubuntu:20.04

RUN apt-get update && apt-get install -y sudo wget vim curl gawk make gcc

RUN wget https://repo.continuum.io/archive/Anaconda3-2019.03-Linux-x86_64.sh &&
sh Anaconda3-2019.03-Linux-x86_64.sh -b &&
rm -f Anaconda3-2019.03-Linux-x86_64.sh &&
sudo curl -sL https://deb.nodesource.com/setup_16.x | sudo bash - &&
sudo apt-get install -y nodejs

ENV PATH $PATH:/root/anaconda3/bin

RUN pip install --upgrade pip RUN pip install pandas_datareader RUN pip install mplfinance

RUN wget --quiet http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz -O ta-lib-0.4.0-src.tar.gz &&
tar -zxvf ta-lib-0.4.0-src.tar.gz &&
cd ta-lib/ &&
./configure --prefix=/usr &&
sudo make &&
sudo make install &&
cd .. &&
pip install TA-Lib &&
rm -R ta-lib ta-lib-0.4.0-src.tar.gz

RUN mkdir /workspace

CMD ["jupyter-lab", "--ip=0.0.0.0","--port=8888" ,"--no-browser", "--allow-root", "--LabApp.token=''"]

Ktachi87 avatar Nov 26 '22 17:11 Ktachi87

Use a newer numpy or regenerate the C files using cython. On Nov 26, 2022, at 9:08 AM, Ktachi87 @.***> wrote: Sorry for the layman's question. Can someone please advise me on this? I tried to analyze stock prices, and I referred to the following site, but I cannot use TA-lib. https://www.youtube.com/watch?v=6R6-BCFd7zM I checked the GITHUB logs and found that it is most likely a problem with some software ver, but I couldn't find an answer in the end. I would like to use TA-lib on Docker in the following environment, but it does not work. python: lastest(docker image --> TAG) numpy: 1.16.2 Followings are the codes I used and error codes. code[jupyter-lab] import pandas as pd import numpy as np import talib as ta from pandas_datareader import data import matplotlib.pyplot as plt %matplotlib inline import warmimgs warnings.simplefilter('ignore') error code[jupyter-lab] ValueError Traceback (most recent call last) in 1 import pandas as pd 2 import numpy as np ----> 3 import talib as ta 4 from pandas_datareader import data 5 import matplotlib.pyplot as plt ~/anaconda3/lib/python3.7/site-packages/talib/init.py in 91 92 ---> 93 from ._ta_lib import ( 94 _ta_initialize, _ta_shutdown, MA_Type, ta_version, 95 _ta_set_unstable_period as set_unstable_period, talib/_ta_lib.pyx in init talib._ta_lib() ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject docker file: FROM ubuntu:20.04 RUN apt-get update && apt-get install -y sudo wget vim curl gawk make gcc RUN wget https://repo.continuum.io/archive/Anaconda3-2019.03-Linux-x86_64.sh && sh Anaconda3-2019.03-Linux-x86_64.sh -b && rm -f Anaconda3-2019.03-Linux-x86_64.sh && sudo curl -sL https://deb.nodesource.com/setup_16.x | sudo bash - && sudo apt-get install -y nodejs ENV PATH $PATH:/root/anaconda3/bin RUN pip install --upgrade pip RUN pip install pandas_datareader RUN pip install mplfinance RUN wget --quiet http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz -O ta-lib-0.4.0-src.tar.gz && tar -zxvf ta-lib-0.4.0-src.tar.gz && cd ta-lib/ && ./configure --prefix=/usr && sudo make && sudo make install && cd .. && pip install TA-Lib && rm -R ta-lib ta-lib-0.4.0-src.tar.gz RUN mkdir /workspace CMD ["jupyter-lab", "--ip=0.0.0.0","--port=8888" ,"--no-browser", "--allow-root", "--LabApp.token=''"]

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.***>

mrjbq7 avatar Nov 26 '22 20:11 mrjbq7

Thank you, Mr.Benediktsson.

Thanks to your advice, I managed to solve the problem on my own. I had heard that "the numpy ver should be changed" but didn't realize it was the latest version.

The following method solved the problem. I wrote "pip install numpy==1.21.6" on the first line on the Jupiter lab. After running this, I wrote upper "code[jupyter-lab]"

This may be useful for many beginner Japanese.

Ktachi87 avatar Nov 27 '22 11:11 Ktachi87