I've come across the excellent piece of work of @mrjbq7 who wrote a Python wrapper for TA-Lib - an open source technical analysis library written in C. I've installed both TA-Lib (easy as the usual configure, make, make install) as well as the wrapper (using the included setup.py script) per the instructions but I am receiving an import error when attempting to import the module or run the example script (same import error).
I'm on a Linux machine (sys.platform == 'linux2') and using the Enthought distribution of Python 2.7.
I've installed TA-Lib to its default location which is pointed to by the wrapper setuptools script (you can see the source of setup.py here):
bash$ ls -la /usr/local/include/ta-lib/
total 240
drwxr-xr-x 2 root root 4096 2012-08-04 08:54 .
drwxr-xr-x 3 root root 4096 2012-08-04 08:54 ..
-rw-r--r-- 1 root root 19930 2012-08-04 08:54 ta_abstract.h
-rw-r--r-- 1 root root 4792 2012-08-04 08:54 ta_common.h
-rw-r--r-- 1 root root 12391 2012-08-04 08:54 ta_defs.h
-rw-r--r-- 1 root root 181115 2012-08-04 08:54 ta_func.h
-rw-r--r-- 1 root root 1849 2012-08-04 08:54 ta_libc.h
bash$ ls -la /usr/local/lib
total 4956
drwxr-xr-x 3 root root 4096 2012-08-04 08:54 .
drwxr-xr-x 12 root root 4096 2011-04-06 23:47 ..
-rw-r--r-- 1 root root 3063180 2012-08-04 08:54 libta_lib.a
-rwxr-xr-x 1 root root 837 2012-08-04 08:54 libta_lib.la
lrwxrwxrwx 1 root root 18 2012-08-04 08:54 libta_lib.so -> libta_lib.so.0.0.0
lrwxrwxrwx 1 root root 18 2012-08-04 08:54 libta_lib.so.0 -> libta_lib.so.0.0.0
-rwxr-xr-x 1 root root 1983243 2012-08-04 08:54 libta_lib.so.0.0.0
drwxr-xr-x 11 root root 4096 2011-04-07 17:10 pythonEPD
Then I successfully build the Cython code using python setup.py install:
bash$ python setup.py install
running install
running build
running build_ext
building 'talib' extension
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -O2 -I/usr/local/lib/pythonEPD/include -fPIC -I/usr/local/lib/pythonEPD/lib/python2.7/site-packages/numpy/core/include -I/usr/local/include/ta-lib/ -I/usr/local/lib/pythonEPD/include/python2.7 -c talib.c -o build/temp.linux-i686-2.7/talib.o
...
[truncated - lots of warnings regarding pointer types]
---
gcc -pthread -shared -g -L/usr/local/lib/pythonEPD/lib build/temp.linux-i686-2.7/talib.o -L/usr/local/lib/ -L. -lta_lib -lpython2.7 -o build/lib.linux-i686-2.7/talib.so
running install_lib
copying build/lib.linux-i686-2.7/talib.so -> /usr/local/lib/pythonEPD/lib/python2.7/site-packages
running install_egg_info
Writing /usr/local/lib/pythonEPD/lib/python2.7/site-packages/TA_Lib-0.4.0-py2.7.egg-info
Yet when I attempt to run the example scripts or import talib, I get the following import eror:
bash$ python
Enthought Python Distribution -- www.enthought.com
Version: 7.0-2 (32-bit)
Python 2.7.1 |EPD 7.0-2 (32-bit)| (r271:86832, Nov 29 2010, 13:52:51)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import talib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: libta_lib.so.0: cannot open shared object file: No such file or directory
The setup.py script clearly includes the appropriate paths to the compiled TA-Lib code in the Extension class but I do notice that the gcc commands in the build of the Cython code do not include reference to the /usr/local/lib path... (not sure if this is the issue?).
I'm hoping someone has come across this with this module or a similar situation?
Close @rcovre, I posted an issue on @mrjbq's github site and he responded with the very simple solution:
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
For the permanent solution, have to add /usr/local/lib to /etc/ld.so.conf as root then run /sbin/ldconfig (also as root).
Works like a charm.
https://github.com/mrjbq7/ta-lib/issues/6
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With