TA-Lib / ta-lib-python

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

Error on import under Python 3.11 #606

Closed Dhaneor closed 8 months ago

Dhaneor commented 1 year ago

When importing talib in virtual environment that uses Python 3.11 I get the following error message:

In [1]: import talib as ta

ImportError Traceback (most recent call last) Cell In [1], line 1 ----> 1 import talib as ta

File ~/opt/anaconda3/envs/bot311/lib/python3.11/site-packages/talib/init.py:93 89 else: 90 _wrapper = lambda x: x ---> 93 from ._ta_lib import ( 94 _ta_initialize, _ta_shutdown, MA_Type, __ta_version, 95 _ta_set_unstable_period as set_unstable_period, 96 _ta_get_unstable_period as get_unstable_period, 97 _ta_set_compatibility as set_compatibility, 98 _ta_get_compatibility as get_compatibility, 99 TA_FUNCTION_NAMES__ 100 ) 102 # import all the func and stream functions 103 from ._ta_lib import *

ImportError: dlopen(/Users/dhaneor/opt/anaconda3/envs/bot311/lib/python3.11/site-packages/talib/_ta_lib.cpython-311-darwin.so, 2): Symbol not found: _TA_ACOS Referenced from: /Users/dhaneor/opt/anaconda3/envs/bot311/lib/python3.11/site-packages/talib/_ta_lib.cpython-311-darwin.so Expected in: flat namespace in /Users/dhaneor/opt/anaconda3/envs/bot311/lib/python3.11/site-packages/talib/_ta_lib.cpython-311-darwin.so

I could not install the package with conda (latest not available on PyPi yet?) because it demands Python to be below version 3.11. I got it installed using the source from Github where this requirement is already updated. The conda installed version in a Python 3.10 environment works just fine, but under 3.11 I get the error message mentioned above.

I don't understand why the file __talib.cpython-311-darwin.so cannot be found, because I can see it in the directory.

(bot311) dhaneor@andromeda$ pwd /Users/dhaneor/opt/anaconda3/envs/bot311/lib/python3.11/site-packages/talib (bot311) dhaneor@andromeda$ ls -l total 2984 -rw-r--r-- 1 dhaneor staff 8879 Aug 3 13:18 init.py drwxr-xr-x 6 dhaneor staff 192 Aug 3 13:18 pycache -rwxr-xr-x 1 dhaneor staff 1502744 Aug 3 13:18 _ta_lib.cpython-311-darwin.so -rw-r--r-- 1 dhaneor staff 799 Aug 3 13:18 abstract.py -rw-r--r-- 1 dhaneor staff 105 Aug 3 13:18 deprecated.py -rw-r--r-- 1 dhaneor staff 186 Aug 3 13:18 stream.py

mrjbq7 commented 1 year ago

The README has all the information on how to install it. You need the underlying TA-Lib C library on the machine. The error is this:Symbol not found: _TA_ACOSInstall TA-lib and then install this Python wrapper.If you are having trouble reading the README installation guide let me know and I can help. On Aug 3, 2023, at 4:31 AM, Dhaneõr @.> wrote: When importing talib in virtual environment that uses Python 3.11 I get the following error message: In [1]: import talib as ta ImportError Traceback (most recent call last) Cell In [1], line 1 ----> 1 import talib as ta File ~/opt/anaconda3/envs/bot311/lib/python3.11/site-packages/talib/init.py:93 89 else: 90 _wrapper = lambda x: x ---> 93 from ._ta_lib import ( 94 _ta_initialize, _ta_shutdown, MA_Type, ta_version, 95 _ta_set_unstable_period as set_unstable_period, 96 _ta_get_unstable_period as get_unstable_period, 97 _ta_set_compatibility as set_compatibility, 98 _ta_get_compatibility as get_compatibility, 99 TA_FUNCTION_NAMES 100 ) 102 # import all the func and stream functions 103 from ._ta_lib import ImportError: dlopen(/Users/dhaneor/opt/anaconda3/envs/bot311/lib/python3.11/site-packages/talib/_ta_lib.cpython-311-darwin.so, 2): Symbol not found: _TA_ACOS Referenced from: /Users/dhaneor/opt/anaconda3/envs/bot311/lib/python3.11/site-packages/talib/_ta_lib.cpython-311-darwin.so Expected in: flat namespace in /Users/dhaneor/opt/anaconda3/envs/bot311/lib/python3.11/site-packages/talib/_ta_lib.cpython-311-darwin.so I could not install the package with conda (latest not available on PyPi yet?) because it demands Python to be below version 3.11. I got it installed using the source from Github where this requirement is already updated. The conda installed version in a Python 3.10 environment works just fine, but under 3.11 I get the error message mentioned above. I don't understand why the file _ta_lib.cpython-311-darwin.so cannot be found, because I can see it in the directory. (bot311) **@.$ pwd /Users/dhaneor/opt/anaconda3/envs/bot311/lib/python3.11/site-packages/talib (bot311) @.$ ls -l total 2984 -rw-r--r-- 1 dhaneor staff 8879 Aug 3 13:18 init.py drwxr-xr-x 6 dhaneor staff 192 Aug 3 13:18 pycache -rwxr-xr-x 1 dhaneor staff 1502744 Aug 3 13:18 _ta_lib.cpython-311-darwin.so -rw-r--r-- 1 dhaneor staff 799 Aug 3 13:18 abstract.py -rw-r--r-- 1 dhaneor staff 105 Aug 3 13:18 deprecated.py -rw-r--r-- 1 dhaneor staff 186 Aug 3 13:18 stream.py

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

Dhaneor commented 1 year ago

Thanks for your answer! I did read the installation instructions, and it works fine with Python 3.10.8 and ta-lib 0.4.19 - so the C library should be installed correctly. This error message only pops up with Python 3.11 and ta-lib 0.4.28, installed from the sources downloaded from here.

mrjbq7 commented 1 year ago

How did you install it it for python 3.11?You need to install the underlying TA-Lib C library and then pip install ta-lib.On Aug 3, 2023, at 12:57 PM, Dhaneõr @.***> wrote: Thanks for your answer! I did read the installation instructions, and it works fine with Python 3.10.8 and ta-lib 0.4.19 - so the C library should be installed correctly. This error message only pops up with Python 3.11 and ta-lib 0.4.28, installed from the sources downloaded from here.

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

Dhaneor commented 1 year ago

I tried again. At first, I installed it by running setup.py:

(bot311) dhaneor@andromeda$ python setup.py install running install /Users/dhaneor/opt/anaconda3/envs/bot311/lib/python3.11/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools. warnings.warn( /Users/dhaneor/opt/anaconda3/envs/bot311/lib/python3.11/site-packages/setuptools/command/easy_install.py:144: EasyInstallDeprecationWarning: easy_install command is deprecated. Use build and pip and other standards-based tools. warnings.warn( running bdist_egg running egg_info writing TA_Lib.egg-info/PKG-INFO writing dependency_links to TA_Lib.egg-info/dependency_links.txt writing requirements to TA_Lib.egg-info/requires.txt writing top-level names to TA_Lib.egg-info/top_level.txt reading manifest file 'TA_Lib.egg-info/SOURCES.txt' reading manifest template 'MANIFEST.in' adding license file 'LICENSE' adding license file 'AUTHORS' writing manifest file 'TA_Lib.egg-info/SOURCES.txt' installing library code to build/bdist.macosx-10.9-x86_64/egg running install_lib running build_py running build_ext creating build/bdist.macosx-10.9-x86_64/egg creating build/bdist.macosx-10.9-x86_64/egg/talib copying build/lib.macosx-10.9-x86_64-cpython-311/talib/abstract.py -> build/bdist.macosx-10.9-x86_64/egg/talib copying build/lib.macosx-10.9-x86_64-cpython-311/talib/deprecated.py -> build/bdist.macosx-10.9-x86_64/egg/talib copying build/lib.macosx-10.9-x86_64-cpython-311/talib/init.py -> build/bdist.macosx-10.9-x86_64/egg/talib copying build/lib.macosx-10.9-x86_64-cpython-311/talib/stream.py -> build/bdist.macosx-10.9-x86_64/egg/talib copying build/lib.macosx-10.9-x86_64-cpython-311/talib/_ta_lib.cpython-311-darwin.so -> build/bdist.macosx-10.9-x86_64/egg/talib byte-compiling build/bdist.macosx-10.9-x86_64/egg/talib/abstract.py to abstract.cpython-311.pyc byte-compiling build/bdist.macosx-10.9-x86_64/egg/talib/deprecated.py to deprecated.cpython-311.pyc byte-compiling build/bdist.macosx-10.9-x86_64/egg/talib/init.py to init.cpython-311.pyc byte-compiling build/bdist.macosx-10.9-x86_64/egg/talib/stream.py to stream.cpython-311.pyc creating stub loader for talib/_ta_lib.cpython-311-darwin.so byte-compiling build/bdist.macosx-10.9-x86_64/egg/talib/_ta_lib.py to _ta_lib.cpython-311.pyc creating build/bdist.macosx-10.9-x86_64/egg/EGG-INFO copying TA_Lib.egg-info/PKG-INFO -> build/bdist.macosx-10.9-x86_64/egg/EGG-INFO copying TA_Lib.egg-info/SOURCES.txt -> build/bdist.macosx-10.9-x86_64/egg/EGG-INFO copying TA_Lib.egg-info/dependency_links.txt -> build/bdist.macosx-10.9-x86_64/egg/EGG-INFO copying TA_Lib.egg-info/requires.txt -> build/bdist.macosx-10.9-x86_64/egg/EGG-INFO copying TA_Lib.egg-info/top_level.txt -> build/bdist.macosx-10.9-x86_64/egg/EGG-INFO writing build/bdist.macosx-10.9-x86_64/egg/EGG-INFO/native_libs.txt zip_safe flag not set; analyzing archive contents... talib.pycache._ta_lib.cpython-311: module references file creating 'dist/TA_Lib-0.4.28-py3.11-macosx-10.9-x86_64.egg' and adding 'build/bdist.macosx-10.9-x86_64/egg' to it removing 'build/bdist.macosx-10.9-x86_64/egg' (and everything under it) Processing TA_Lib-0.4.28-py3.11-macosx-10.9-x86_64.egg removing '/Users/dhaneor/opt/anaconda3/envs/bot311/lib/python3.11/site-packages/TA_Lib-0.4.28-py3.11-macosx-10.9-x86_64.egg' (and everything under it) creating /Users/dhaneor/opt/anaconda3/envs/bot311/lib/python3.11/site-packages/TA_Lib-0.4.28-py3.11-macosx-10.9-x86_64.egg Extracting TA_Lib-0.4.28-py3.11-macosx-10.9-x86_64.egg to /Users/dhaneor/opt/anaconda3/envs/bot311/lib/python3.11/site-packages TA-Lib 0.4.28 is already the active version in easy-install.pth

Installed /Users/dhaneor/opt/anaconda3/envs/bot311/lib/python3.11/site-packages/TA_Lib-0.4.28-py3.11-macosx-10.9-x86_64.egg Processing dependencies for TA-Lib==0.4.28 Searching for numpy==1.24.4 Best match: numpy 1.24.4 Adding numpy 1.24.4 to easy-install.pth file Installing f2py script to /Users/dhaneor/opt/anaconda3/envs/bot311/bin Installing f2py3 script to /Users/dhaneor/opt/anaconda3/envs/bot311/bin Installing f2py3.11 script to /Users/dhaneor/opt/anaconda3/envs/bot311/bin

Using /Users/dhaneor/opt/anaconda3/envs/bot311/lib/python3.11/site-packages Finished processing dependencies for TA-Lib==0.4.28

Then I ran test_func.py, which again, produces the error message:

(bot311) dhaneor@andromeda$ python test_func.py Traceback (most recent call last): File "/Users/dhaneor/Documents/python stuff/ta-lib-python-master/tests/test_func.py", line 5, in import talib File "/Users/dhaneor/opt/anaconda3/envs/bot311/lib/python3.11/site-packages/TA_Lib-0.4.28-py3.11-macosx-10.9-x86_64.egg/talib/init.py", line 93, in from ._ta_lib import ( ImportError: dlopen(/Users/dhaneor/opt/anaconda3/envs/bot311/lib/python3.11/site-packages/TA_Lib-0.4.28-py3.11-macosx-10.9-x86_64.egg/talib/_ta_lib.cpython-311-darwin.so, 2): Symbol not found: _TA_ACOS Referenced from: /Users/dhaneor/opt/anaconda3/envs/bot311/lib/python3.11/site-packages/TA_Lib-0.4.28-py3.11-macosx-10.9-x86_64.egg/talib/_ta_lib.cpython-311-darwin.so Expected in: flat namespace in /Users/dhaneor/opt/anaconda3/envs/bot311/lib/python3.11/site-packages/TA_Lib-0.4.28-py3.11-macosx-10.9-x86_64.egg/talib/_ta_lib.cpython-311-darwin.so

The I uninstalled and reinstalled ta-lib with pip:

(bot311) dhaneor@andromeda$ pip uninstall ta-lib DEPRECATION: Loading egg at /Users/dhaneor/opt/anaconda3/envs/bot311/lib/python3.11/site-packages/TA_Lib-0.4.28-py3.11-macosx-10.9-x86_64.egg is deprecated. pip 23.3 will enforce this behaviour change. A possible replacement is to use pip for package installation.. Found existing installation: TA-Lib 0.4.28 Uninstalling TA-Lib-0.4.28: Would remove: /Users/dhaneor/opt/anaconda3/envs/bot311/lib/python3.11/site-packages/TA_Lib-0.4.28-py3.11-macosx-10.9-x86_64.egg Proceed (Y/n)? Successfully uninstalled TA-Lib-0.4.28 (bot311) dhaneor@andromeda$ pip install ta-lib Collecting ta-lib Using cached TA-Lib-0.4.27.tar.gz (266 kB) Installing build dependencies ... done Getting requirements to build wheel ... done Installing backend dependencies ... done Preparing metadata (pyproject.toml) ... done Requirement already satisfied: numpy in /Users/dhaneor/opt/anaconda3/envs/bot311/lib/python3.11/site-packages (from ta-lib) (1.23.5) 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.27-cp311-cp311-macosx_10_9_x86_64.whl size=381891 sha256=f9e22c83b172461b15a112dacc1aad56bd76f71cc672ad4e9c34b07c50c462cb Stored in directory: /Users/dhaneor/Library/Caches/pip/wheels/52/0b/93/6288de57fcfc637509e6b9a7f8406b8d78aa87a34be37eb2b7 Successfully built ta-lib Installing collected packages: ta-lib Successfully installed ta-lib-0.4.27

Then, when I run test_func.py, I still get the error message. After switching to another environment, it works just fine, though. Shouldn't the installation of the C library be fine, if it works with Python 3.10.8?

(bot311) dhaneor@andromeda$ python test_func.py Traceback (most recent call last): File "/Users/dhaneor/Documents/python stuff/ta-lib-python-master/tests/test_func.py", line 5, in import talib File "/Users/dhaneor/opt/anaconda3/envs/bot311/lib/python3.11/site-packages/talib/init.py", line 93, in from ._ta_lib import ( ImportError: dlopen(/Users/dhaneor/opt/anaconda3/envs/bot311/lib/python3.11/site-packages/talib/_ta_lib.cpython-311-darwin.so, 2): Symbol not found: _TA_ACOS Referenced from: /Users/dhaneor/opt/anaconda3/envs/bot311/lib/python3.11/site-packages/talib/_ta_lib.cpython-311-darwin.so Expected in: flat namespace in /Users/dhaneor/opt/anaconda3/envs/bot311/lib/python3.11/site-packages/talib/_ta_lib.cpython-311-darwin.so (bot311) dhaneor@andromeda$ conda activate bot310 (bot310) dhaneor@andromeda$ python test_func.py
(bot310) dhaneor@andromeda$ ls

mrjbq7 commented 8 months ago

Closing old issue.