我遇到了@mrjbq7 的出色工作,他为TA-Lib编写了一个 Python包装器——一个用 C 编写的开源技术分析库。我已经安装了两个 TA-Lib(像往常一样简单,,,)以及包装器(使用包含的 setup.py 脚本),但我在尝试导入模块或运行示例脚本时收到导入错误(相同的导入错误)。configure
make
make install
我在 Linux 机器 ( sys.platform == 'linux2'
) 上并使用 Python 2.7 的 Enthought 发行版。
我已将 TA-Lib 安装到包装脚本指向的默认位置(您可以在此处setuptools
查看 setup.py 的源代码):
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
然后我使用以下方法成功构建了 Cython 代码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
然而,当我尝试运行示例脚本或导入 talib 时,我收到以下导入错误:
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
setup.py 脚本清楚地包括扩展类中已编译 TA-Lib 代码的适当路径,但我注意到gcc
Cython 代码构建中的命令不包括对/usr/local/lib
路径的引用......(不确定这是否是问题吗?)。
我希望有人在这个模块或类似情况下遇到过这个问题?