TA-Lib / ta-lib-python

Python wrapper for TA-Lib (http://ta-lib.org/).
http://ta-lib.github.io/ta-lib-python
Other
9.79k stars 1.78k forks source link

Unable to import talib in Google colab #590

Closed KPCA1994 closed 1 year ago

KPCA1994 commented 1 year ago

Unable to import talib in Google Colab. Getting error

"RuntimeError                              Traceback (most recent call last)
__init__.pxd in numpy.import_array()

RuntimeError: module compiled against API version 0x10 but this version of numpy is 0xf . 
Check the section C-API incompatibility at the Troubleshooting ImportError section at
https://numpy.org/devdocs/user/troubleshooting-importerror.html#c-api-incompatibility
for indications on how to solve this problem .

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
[<ipython-input-24-1ee486ccef90>](https://localhost:8080/#) in <cell line: 1>()
----> 1 import talib

[/usr/local/lib/python3.9/dist-packages/talib/__init__.py](https://localhost:8080/#) in <module>
     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/_func.pxi in init talib._ta_lib()

__init__.pxd in numpy.import_array()

ImportError: numpy.core.multiarray failed to import"
mrjbq7 commented 1 year ago

The easiest fix is updating your numpy to a newer version.

It is true that I generate the C files with a recent version of numpy, so if you want to try using your existing numpy, you can: git checkout ta-lib-python, delete the C files, or regenerate them with make cython, and then python setup.py install...

chattel-tech commented 1 year ago

Downloading TA-Lib-0.4.26.tar.gz (272 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 272.6/272.6 kB 9.7 MB/s eta 0:00:00 Installing build dependencies ... done Getting requirements to build wheel ... done Installing backend dependencies ... done Preparing metadata (pyproject.toml) ... done Requirement already satisfied: numpy in /usr/local/lib/python3.9/dist-packages (from TA-Lib) (1.22.4) Building wheels for collected packages: TA-Lib Building wheel for TA-Lib (pyproject.toml) ... done Created wheel for TA-Lib: filename=TA_Lib-0.4.26-cp39-cp39-linux_x86_64.whl size=2261745 sha256=9afadc9f64c61100d533468664d83a39ea616a7a94da435595ed611c12aacc88 Stored in directory: /root/.cache/pip/wheels/05/d1/3c/8846d2115d6b73b448af7f8e361bf267a1d82b87e318bc18cb Successfully built TA-Lib Installing collected packages: TA-Lib Successfully installed TA-Lib-0.4.26

I have latest numpy still getting the same error

mrjbq7 commented 1 year ago

@chattel-tech

It looks like you have numpy 1.22.4? I think latest is 1.23.2.

When you say getting the same error, it's on import of ta-lib?

uirty commented 1 year ago

[Google Colab]Execute in order

!pip install numpy==1.23.2 OR !pip install --upgrade numpy

Restart execution phase [Ctrl+M .]

install Ta-Lib

import talib

rarben commented 1 year ago

@KPCA1994 @uirty @mrjbq7 May I ask if this problem has been solved? Because I also have the same problem.

The following procedure can be executed on the google colab platform to install Talib completely, but there will be an exception at the import stage.

install talib ''''''''''''''' !wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz !tar -xzvf ta-lib-0.4.0-src.tar.gz %cd ta-lib !./configure --prefix=/usr !make !make install !pip install TA-lib

!pip install talib-binary

url = 'https://anaconda.org/conda-forge/libta-lib/0.4.0/download/linux-64/libta-lib-0.4.0-h166bdaf_1.tar.bz2' !curl -L $url | tar xj -C /usr/lib/x86_64-linux-gnu/ lib --strip-components=1 url = 'https://anaconda.org/conda-forge/ta-lib/0.4.19/download/linux-64/ta-lib-0.4.19-py39hd257fcd_4.tar.bz2'#!curl -L $url | tar xj -C /usr/local/lib/python3.10/dist-packages/ lib/python3.10/site-packages/talib --strip-components=3 !curl -L $url | tar xj -C /usr/local/lib/python3.10/dist-packages/talib --strip-components=3

/content/ta-lib

!pip install numpy==1.23.2 import talib ''''''''''''''''''''''

error logs '''''''''''''''''''''' Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/ Collecting TA-lib Downloading TA-Lib-0.4.26.tar.gz (272 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 272.6/272.6 kB 5.4 MB/s eta 0:00:00 Installing build dependencies ... done Getting requirements to build wheel ... done Installing backend dependencies ... done Preparing metadata (pyproject.toml) ... done Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from TA-lib) (1.22.4) Building wheels for collected packages: TA-lib Building wheel for TA-lib (pyproject.toml) ... done Created wheel for TA-lib: filename=TA_Lib-0.4.26-cp310-cp310-linux_x86_64.whl size=2239033 sha256=370ba7c2f97d49110100df6f8b021663bfa373e66dba7064193254505d4112d2 Stored in directory: /root/.cache/pip/wheels/ad/be/fe/93a0b4e4efd7fbb963157b79d512c747e935be08fc7b9e3a53 Successfully built TA-lib Installing collected packages: TA-lib Successfully installed TA-lib-0.4.26 % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 4311 0 4311 0 0 18423 0 --:--:-- --:--:-- --:--:-- 18423 100 517k 100 517k 0 0 802k 0 --:--:-- --:--:-- --:--:-- 1746k % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 4387 0 4387 0 0 19411 0 --:--:-- --:--:-- --:--:-- 19411 100 389k 100 389k 0 0 749k 0 --:--:-- --:--:-- --:--:-- 749k Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/ Collecting numpy==1.23.2 Downloading numpy-1.23.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.0 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 17.0/17.0 MB 65.7 MB/s eta 0:00:00 Installing collected packages: numpy Attempting uninstall: numpy Found existing installation: numpy 1.22.4 Uninstalling numpy-1.22.4: Successfully uninstalled numpy-1.22.4 Successfully installed numpy-1.23.2 WARNING: The following packages were previously imported in this runtime: [numpy] You must restart the runtime in order to use newly installed versions.

RuntimeError Traceback (most recent call last) init.pxd in numpy.import_array()

RuntimeError: module compiled against API version 0x10 but this version of numpy is 0xf . Check the section C-API incompatibility at the Troubleshooting ImportError section at https://numpy.org/devdocs/user/troubleshooting-importerror.html#c-api-incompatibility for indications on how to solve this problem .

During handling of the above exception, another exception occurred:

ImportError Traceback (most recent call last) in <cell line: 15>() 13 #/content/ta-lib 14 get_ipython().system('pip install numpy==1.23.2') ---> 15 import talib

/usr/local/lib/python3.10/dist-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/_func.pxi in init talib._ta_lib()

init.pxd in numpy.import_array()

ImportError: numpy.core.multiarray failed to import


'''''''''''''''''''''

KPCA1994 commented 1 year ago

Issue still exists in google colab. Working fine in jupyter notebook with latest numpy version.

uirty commented 1 year ago

@rarben I don't understand why you can't use it, I don't have an abnormal condition.

!pip install pandas
!pip install numpy==1.23.2
!pip install FinMind
!pip install yfinance
!pip install mplfinance
!pip install lineTool
!pip install requests

Restart execution phase [Ctrl+M .]


!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
!rm -rf *.so
!rm -rf *.c
!./configure --prefix=/usr
!make
!make install
!pip install Ta-Lib
import talib
KPCA1994 commented 1 year ago

@uirty working fine with your code. Closing the issue.