在Ubuntu 16 Python3上安装TA-Lib时出错

时间:2018-09-19 00:30:00

标签: python ubuntu pip ta-lib

我正在使用Ubuntu 16:

$ pip -V
pip 18.0 from /home/XYZ-ubuntu/.local/lib/python3.6/site-packages/pip (python 3.6)
XYZ-ubuntu@XYZubuntu-desktop:~/Desktop/MCF/BitMEX-simple-trading-robot-master$ pip3 -V
pip 18.0 from /home/usm-ubuntu/.local/lib/python3.6/site-packages/pip (python 3.6)

运行此命令时:

  

pip安装TA-lib

我收到以下错误:

$ pip 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 /home/usm-ubuntu/.local/lib/python3.6/site-packages (from TA-lib) (1.15.1)
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-install-72o18u12/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/pip-wheel-3i94vijy --python-tag cp36:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.6
  creating build/lib.linux-x86_64-3.6/talib
  copying talib/abstract.py -> build/lib.linux-x86_64-3.6/talib
  copying talib/test_func.py -> build/lib.linux-x86_64-3.6/talib
  copying talib/test_pandas.py -> build/lib.linux-x86_64-3.6/talib
  copying talib/stream.py -> build/lib.linux-x86_64-3.6/talib
  copying talib/__init__.py -> build/lib.linux-x86_64-3.6/talib
  copying talib/test_stream.py -> build/lib.linux-x86_64-3.6/talib
  copying talib/test_abstract.py -> build/lib.linux-x86_64-3.6/talib
  copying talib/test_data.py -> build/lib.linux-x86_64-3.6/talib
  copying talib/deprecated.py -> build/lib.linux-x86_64-3.6/talib
  running build_ext
  building 'talib._ta_lib' extension
  creating build/temp.linux-x86_64-3.6
  creating build/temp.linux-x86_64-3.6/talib
  x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/usm-ubuntu/.local/lib/python3.6/site-packages/numpy/core/include -I/usr/include -I/usr/local/include -I/opt/include -I/opt/local/include -I/usr/include/python3.6m -c talib/_ta_lib.c -o build/temp.linux-x86_64-3.6/talib/_ta_lib.o
  talib/_ta_lib.c:4:20: fatal error: Python.h: No such file or directory
  compilation terminated.
  error: command 'x86_64-linux-gnu-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-install-72o18u12/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-record-bsagqzqb/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.6
    creating build/lib.linux-x86_64-3.6/talib
    copying talib/abstract.py -> build/lib.linux-x86_64-3.6/talib
    copying talib/test_func.py -> build/lib.linux-x86_64-3.6/talib
    copying talib/test_pandas.py -> build/lib.linux-x86_64-3.6/talib
    copying talib/stream.py -> build/lib.linux-x86_64-3.6/talib
    copying talib/__init__.py -> build/lib.linux-x86_64-3.6/talib
    copying talib/test_stream.py -> build/lib.linux-x86_64-3.6/talib
    copying talib/test_abstract.py -> build/lib.linux-x86_64-3.6/talib
    copying talib/test_data.py -> build/lib.linux-x86_64-3.6/talib
    copying talib/deprecated.py -> build/lib.linux-x86_64-3.6/talib
    running build_ext
    building 'talib._ta_lib' extension
    creating build/temp.linux-x86_64-3.6
    creating build/temp.linux-x86_64-3.6/talib
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/usm-ubuntu/.local/lib/python3.6/site-packages/numpy/core/include -I/usr/include -I/usr/local/include -I/opt/include -I/opt/local/include -I/usr/include/python3.6m -c talib/_ta_lib.c -o build/temp.linux-x86_64-3.6/talib/_ta_lib.o
    talib/_ta_lib.c:4:20: fatal error: Python.h: No such file or directory
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

    ----------------------------------------
Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-72o18u12/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-record-bsagqzqb/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-72o18u12/TA-lib/

我已经关注了这里的所有内容-

  

Unable to install TA-Lib on Ubuntu

我已经花了几个小时对此进行了搜索,但都无济于事。有没有人有办法解决吗?谢谢

1 个答案:

答案 0 :(得分:0)

我通过升级到Ubuntu 18.04 LTS解决了此问题。我在2.7和3.5 / 3.6之间有冲突。

升级后,我使用nano ~/.bashrc并添加行alias python = python3将别名更改为python3。

然后通过运行命令安装TA-lib:

  

python3 -m pip安装TA-lib

现在一切正常。谢谢