# Python Fintech 學習筆記 : 安裝技術指標套件 TA-Lib
TA-Lib 官網 :
# http://www.ta-lib.org/
# http://www.ta-lib.org/hdr_dw.html (下載)
首先直接用 pip3 安裝 (用 sudo 權限) :
pi@raspberrypi:~ $ sudo pip3 install TA-Lib
Collecting TA-Lib
Downloading https://files.pythonhosted.org/packages/90/05/d4c6a778d7a7de0be366bc4a850b4ffaeac2abad927f95fa8ba6f355a082/TA-Lib-0.4.17.tar.gz (717kB)
Requirement already satisfied: numpy in /usr/lib/python3/dist-packages (from TA-Lib)
Building wheels for collected packages: TA-Lib
Running setup.py bdist_wheel for TA-Lib ... error
Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-dslxq_83/TA-Lib/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmpenqqpi1bpip-wheel- --python-tag cp35:
/tmp/pip-build-dslxq_83/TA-Lib/setup.py:79: UserWarning: Cannot find ta-lib library, installation may fail.
warnings.warn('Cannot find ta-lib library, installation may fail.')
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-armv7l-3.5
creating build/lib.linux-armv7l-3.5/talib
copying talib/test_stream.py -> build/lib.linux-armv7l-3.5/talib
copying talib/stream.py -> build/lib.linux-armv7l-3.5/talib
copying talib/test_func.py -> build/lib.linux-armv7l-3.5/talib
copying talib/test_data.py -> build/lib.linux-armv7l-3.5/talib
copying talib/__init__.py -> build/lib.linux-armv7l-3.5/talib
copying talib/test_pandas.py -> build/lib.linux-armv7l-3.5/talib
copying talib/deprecated.py -> build/lib.linux-armv7l-3.5/talib
copying talib/abstract.py -> build/lib.linux-armv7l-3.5/talib
copying talib/test_abstract.py -> build/lib.linux-armv7l-3.5/talib
running build_ext
building 'talib._ta_lib' extension
creating build/temp.linux-armv7l-3.5
creating build/temp.linux-armv7l-3.5/talib
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.5-6waWnr/python3.5-3.5.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/lib/python3/dist-packages/numpy/core/include -I/usr/include -I/usr/local/include -I/opt/include -I/opt/local/include -I/usr/include/python3.5m -c talib/_ta_lib.c -o build/temp.linux-armv7l-3.5/talib/_ta_lib.o
talib/_ta_lib.c:526:28: fatal error: ta-lib/ta_defs.h: 沒有此一檔案或目錄
#include "ta-lib/ta_defs.h"
^
compilation terminated.
error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1
----------------------------------------
Failed building wheel for TA-Lib
Running setup.py clean for TA-Lib
Failed to build TA-Lib
Installing collected packages: TA-Lib
Running setup.py install for TA-Lib ... error
Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-dslxq_83/TA-Lib/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-jmajbz3n-record/install-record.txt --single-version-externally-managed --compile:
/tmp/pip-build-dslxq_83/TA-Lib/setup.py:79: UserWarning: Cannot find ta-lib library, installation may fail.
warnings.warn('Cannot find ta-lib library, installation may fail.')
running install
running build
running build_py
creating build
creating build/lib.linux-armv7l-3.5
creating build/lib.linux-armv7l-3.5/talib
copying talib/test_stream.py -> build/lib.linux-armv7l-3.5/talib
copying talib/stream.py -> build/lib.linux-armv7l-3.5/talib
copying talib/test_func.py -> build/lib.linux-armv7l-3.5/talib
copying talib/test_data.py -> build/lib.linux-armv7l-3.5/talib
copying talib/__init__.py -> build/lib.linux-armv7l-3.5/talib
copying talib/test_pandas.py -> build/lib.linux-armv7l-3.5/talib
copying talib/deprecated.py -> build/lib.linux-armv7l-3.5/talib
copying talib/abstract.py -> build/lib.linux-armv7l-3.5/talib
copying talib/test_abstract.py -> build/lib.linux-armv7l-3.5/talib
running build_ext
building 'talib._ta_lib' extension
creating build/temp.linux-armv7l-3.5
creating build/temp.linux-armv7l-3.5/talib
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.5-6waWnr/python3.5-3.5.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/lib/python3/dist-packages/numpy/core/include -I/usr/include -I/usr/local/include -I/opt/include -I/opt/local/include -I/usr/include/python3.5m -c talib/_ta_lib.c -o build/temp.linux-armv7l-3.5/talib/_ta_lib.o
talib/_ta_lib.c:526:28: fatal error: ta-lib/ta_defs.h: 沒有此一檔案或目錄
#include "ta-lib/ta_defs.h"
^
compilation terminated.
error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1
----------------------------------------
Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-dslxq_83/TA-Lib/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-jmajbz3n-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-dslxq_83/TA-Lib/
pi@raspberrypi:~ $ wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.17-src.tar.gz
--2019-04-08 00:25:34-- http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.17-src.tar.g.
正在查找主機 prdownloads.sourceforge.net (prdownloads.sourceforge.net)... 216.105.38.13
正在連接 prdownloads.sourceforge.net (prdownloads.sourceforge.net)|216.105.38.13|:80... 連上了。
已送出 HTTP 要求,正在等候回應... 404 Not Found
2019-04-08 00:25:34 錯誤 404: Not Found。
在 Sourceforge 上只能找到 0.4.0 版, 不過沒關係還是可以順利安裝 0.4.17 的, 下載網頁參考 :
# https://sourceforge.net/projects/ta-lib/files/ta-lib/0.4.0/
下載網址是 :
https://sourceforge.net/projects/ta-lib/files/ta-lib/0.4.0/ta-lib-0.4.0-src.tar.gz
pi@raspberrypi:~ $ wget https://sourceforge.net/projects/ta-lib/files/ta-lib/0.4.0/ta-lib-0.4.0-src.tar.gz
--2019-04-07 23:33:58-- https://sourceforge.net/projects/ta-lib/files/ta-lib/0.4.0/ta-lib-0.4.0-src.tar.gz
正在查找主機 sourceforge.net (sourceforge.net)... 216.105.38.13
正在連接 sourceforge.net (sourceforge.net)|216.105.38.13|:443... 連上了。
已送出 HTTP 要求,正在等候回應... 301 Moved Permanently
位置: https://sourceforge.net/projects/ta-lib/files/ta-lib/0.4.0/ta-lib-0.4.0-src.tar.gz/ [跟隨至新的 URL]
--2019-04-07 23:33:59-- https://sourceforge.net/projects/ta-lib/files/ta-lib/0.4.0/ta-lib-0.4.0-src.tar.gz/
正在連接 sourceforge.net (sourceforge.net)|216.105.38.13|:443... 連上了。
已送出 HTTP 要求,正在等候回應... 302 Found
位置: https://sourceforge.net/projects/ta-lib/files/ta-lib/0.4.0/ta-lib-0.4.0-src.tar.gz/download [跟隨至新的 URL]
--2019-04-07 23:34:00-- https://sourceforge.net/projects/ta-lib/files/ta-lib/0.4.0/ta-lib-0.4.0-src.tar.gz/download
正在連接 sourceforge.net (sourceforge.net)|216.105.38.13|:443... 連上了。
已送出 HTTP 要求,正在等候回應... 302 Found
位置: https://downloads.sourceforge.net/project/ta-lib/ta-lib/0.4.0/ta-lib-0.4.0-src.tar.gz?r=&ts=1554651241&use_mirror=nchc [跟隨至新的 URL]
--2019-04-07 23:34:01-- https://downloads.sourceforge.net/project/ta-lib/ta-lib/0.4.0/ta-lib-0.4.0-src.tar.gz?r=&ts=1554651241&use_mirror=nchc
正在查找主機 downloads.sourceforge.net (downloads.sourceforge.net)... 216.105.38.13
正在連接 downloads.sourceforge.net (downloads.sourceforge.net)|216.105.38.13|:443... 連上了。
已送出 HTTP 要求,正在等候回應... 302 Found
位置: https://nchc.dl.sourceforge.net/project/ta-lib/ta-lib/0.4.0/ta-lib-0.4.0-src.tar.gz [跟隨至新的 URL]
--2019-04-07 23:34:02-- https://nchc.dl.sourceforge.net/project/ta-lib/ta-lib/0.4.0/ta-lib-0.4.0-src.tar.gz
正在查找主機 nchc.dl.sourceforge.net (nchc.dl.sourceforge.net)... 211.79.60.17, 2001:e10:ffff:1f02::17
正在連接 nchc.dl.sourceforge.net (nchc.dl.sourceforge.net)|211.79.60.17|:443... 連上了。
已送出 HTTP 要求,正在等候回應... 200 OK
長度: 1330299 (1.3M) [application/x-gzip]
Saving to: ‘ta-lib-0.4.0-src.tar.gz’
ta-lib-0.4.0-src.ta 100%[===================>] 1.27M 613KB/s in 2.1s
2019-04-07 23:34:04 (613 KB/s) - ‘ta-lib-0.4.0-src.tar.gz’ saved [1330299/1330299]
其餘程序一樣, 指令如下 :
$ wget https://sourceforge.net/projects/ta-lib/files/ta-lib/0.4.0/ta-lib-0.4.0-src.tar.gz
$ tar -xvf ta-lib-0.4.0-src.tar.gz $ cd ta-lib
$ ./configure --prefix=/usr
$ sudo make
$ sudo make install
$ sudo pip3 install ta-lib
pi@raspberrypi:~/ta-lib $ sudo pip3 install ta-lib
Collecting ta-lib
Using cached https://files.pythonhosted.org/packages/90/05/d4c6a778d7a7de0be366bc4a850b4ffaeac2abad927f95fa8ba6f355a082/TA-Lib-0.4.17.tar.gz
Requirement already satisfied: numpy in /usr/lib/python3/dist-packages (from ta-lib)
Building wheels for collected packages: ta-lib
Running setup.py bdist_wheel for ta-lib ... - done
Stored in directory: /root/.cache/pip/wheels/2a/2e/ec/71c565b2e0091e03a2b56abfbfd062f14a01a8d7b20ffe8bd5
Successfully built ta-lib
Installing collected packages: ta-lib
Successfully installed ta-lib-0.4.17
進入 Python3 IDLE 測試 OK :
pi@raspberrypi:~ $ python3
Python 3.5.3 (default, Sep 27 2018, 17:25:39)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import talib
>>> import numpy as np
>>> close=np.random.random(30)
>>> print(talib.SMA(close, 5))
[ nan nan nan nan 0.5571889 0.7214722
0.65454713 0.61591527 0.62336662 0.51323451 0.51462813 0.57158732
0.53625824 0.55295428 0.52523956 0.49551231 0.34992363 0.33697378
0.36401168 0.33327995 0.30014998 0.44404003 0.45219654 0.49620899
0.66500719 0.74665869 0.65137001 0.76620986 0.67942667 0.66043455]
# https://www.dropbox.com/s/6ylt98hv1v7kl5t/ta-lib-0.4.0-src.tar.gz?dl=0
# https://www.dropbox.com/s/c7feveef6mr1alp/TA-Lib-0.4.17.tar.gz?dl=0
注意, 安裝編譯過程中若畫面停住不動是正常的, 不要以為是當機了, 要耐心等候.
參考 :
# https://github.com/mrjbq7/ta-lib
# IT資訊戰 [python]TA-Lib 安裝
"IT資訊戰" 此篇提到 Linux 還有一個安裝方式 :
git clone https://github.com/mrjbq7/ta-lib.git
cd ta-lib
python setup.py install
改天用另外一塊樹莓派安裝看看能否成功.
另外要注意的是, 安裝 ta-lib 前須先安裝 Numpy, 參考 :
# 【机器学习】ubuntu / mac / windows环境下TA-Lib安装
# https://sourceforge.net/projects/ta-lib/files/ta-lib/0.4.0/
# TA-Lib Install Error
沒有留言:
張貼留言