Building wheel for TA-Lib (setup.py) ... error / ERROR: Failed building wheel for TA-Lib

Ubuntu18.04
正常的可以Building wheels for collected packages: TA-Lib,所以问题原因:没有wheel for TA-Lib ,网上的大部分都是介绍Windows的wheel,可能是Windows容易出现这问题,但我的是自己找的Linux新版本,可能缺很多包,包括wheel。如果你觉得某些步骤不需要请能告诉我,因为有些步骤可能是没必要,是为应对当时情况做测试。反正没坏处。

(dm) hellopython@ubuntu:~$ 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 ./.virtualenvs/dm/lib/python3.6/site-packages (from TA-Lib) (1.14.2)
Building wheels for collected packages: TA-Lib
  Building wheel for TA-Lib (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /home/hellopython/.virtualenvs/dm/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-2wb288y3/TA-Lib/setup.py'"'"'; __file__='"'"'/tmp/pip-install-2wb288y3/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-tu131bdx --python-tag cp36
       cwd: /tmp/pip-install-2wb288y3/TA-Lib/
  Complete output (25 lines):
  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_data.py -> build/lib.linux-x86_64-3.6/talib
  copying talib/deprecated.py -> build/lib.linux-x86_64-3.6/talib
  copying talib/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_pandas.py -> build/lib.linux-x86_64-3.6/talib
  copying talib/__init__.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_stream.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 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/hellopython/.virtualenvs/dm/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 -I/home/hellopython/.virtualenvs/dm/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:10: fatal error: Python.h: No such file or directory
   #include "Python.h"
            ^~~~~~~~~~
  compilation terminated.
  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
  ----------------------------------------
  ERROR: 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
    ERROR: Command errored out with exit status 1:
     command: /home/hellopython/.virtualenvs/dm/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-2wb288y3/TA-Lib/setup.py'"'"'; __file__='"'"'/tmp/pip-install-2wb288y3/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-aibubswe/install-record.txt --single-version-externally-managed --compile --install-headers /home/hellopython/.virtualenvs/dm/include/site/python3.6/TA-Lib
         cwd: /tmp/pip-install-2wb288y3/TA-Lib/
    Complete output (25 lines):
    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_data.py -> build/lib.linux-x86_64-3.6/talib
    copying talib/deprecated.py -> build/lib.linux-x86_64-3.6/talib
    copying talib/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_pandas.py -> build/lib.linux-x86_64-3.6/talib
    copying talib/__init__.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_stream.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 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/hellopython/.virtualenvs/dm/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 -I/home/hellopython/.virtualenvs/dm/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:10: fatal error: Python.h: No such file or directory
     #include "Python.h"
              ^~~~~~~~~~
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /home/hellopython/.virtualenvs/dm/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-2wb288y3/TA-Lib/setup.py'"'"'; __file__='"'"'/tmp/pip-install-2wb288y3/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-aibubswe/install-record.txt --single-version-externally-managed --compile --install-headers /home/hellopython/.virtualenvs/dm/include/site/python3.6/TA-Lib Check the logs for full command output.

参考:https://blog.csdn.net/qq_41672744/article/details/87774853
我已经把 sudo apt-get install libssl-dev libffi-dev python-dev build-essential libxml2-dev libxslt1-dev 搞定后再做如下:

(dm) hellopython@ubuntu:~$ sudo apt-get install libssl-dev libffi-dev python-dev build-essential libxml2-dev libxslt1-dev
.......省略。

(dm) hellopython@ubuntu:~$ sudo pip install TA-Lib
Traceback (most recent call last):
  File "/usr/bin/pip", line 9, in <module>
    from pip import main
ImportError: cannot import name main

(dm) hellopython@ubuntu:~$ sudo gedit /usr/bin/pip

在打开的文本中把原本的3行代码注释掉,粘贴上新的3行内容后关闭文本,如下:

#from pip import main
#if __name__ == '__main__':
#   sys.exit(main())

from pip import __main__
if __name__ == '__main__':
    sys.exit(__main__._main())

参考:http://www.mamicode.com/info-detail-2669962.html

(dm) hellopython@ubuntu:~$ sudo pip install TA-Lib
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
WARNING: The directory '/home/hellopython/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
WARNING: The directory '/home/hellopython/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting TA-Lib
  Downloading https://files.pythonhosted.org/packages/90/05/d4c6a778d7a7de0be366bc4a850b4ffaeac2abad927f95fa8ba6f355a082/TA-Lib-0.4.17.tar.gz (717kB)
     |████████████████████████████████| 727kB 405kB/s 
Collecting numpy
  Downloading https://files.pythonhosted.org/packages/d7/b1/3367ea1f372957f97a6752ec725b87886e12af1415216feec9067e31df70/numpy-1.16.5-cp27-cp27mu-manylinux1_x86_64.whl (17.0MB)
     |████████████████████████████████| 17.0MB 4.6MB/s 
Building wheels for collected packages: TA-Lib
  Building wheel for TA-Lib (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-HwVNMe/TA-Lib/setup.py'"'"'; __file__='"'"'/tmp/pip-install-HwVNMe/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-VYFZsS --python-tag cp27
       cwd: /tmp/pip-install-HwVNMe/TA-Lib/
  Complete output (5 lines):
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/tmp/pip-install-HwVNMe/TA-Lib/setup.py", line 62, in <module>
      import numpy
  ImportError: No module named numpy
  ----------------------------------------
  ERROR: Failed building wheel for TA-Lib
  Running setup.py clean for TA-Lib
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-HwVNMe/TA-Lib/setup.py'"'"'; __file__='"'"'/tmp/pip-install-HwVNMe/TA-Lib/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' clean --all
       cwd: /tmp/pip-install-HwVNMe/TA-Lib
  Complete output (5 lines):
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/tmp/pip-install-HwVNMe/TA-Lib/setup.py", line 62, in <module>
      import numpy
  ImportError: No module named numpy
  ----------------------------------------
  ERROR: Failed cleaning build dir for TA-Lib
Failed to build TA-Lib
Installing collected packages: numpy, TA-Lib
    Running setup.py install for TA-Lib ... done
Successfully installed TA-Lib-0.4.17 numpy-1.16.5

hellopython@ubuntu:/usr/local/bin$ pip3 install wheel
Collecting wheel
  Using cached https://files.pythonhosted.org/packages/00/83/b4a77d044e78ad1a45610eb88f745be2fd2c6d658f9798a15e384b7d57c9/wheel-0.33.6-py2.py3-none-any.whl
Installing collected packages: wheel
Successfully installed wheel-0.33.6

hellopython@ubuntu:/usr/local/bin$ pip3 install TA-Lib
Collecting TA-Lib
  Using cached https://files.pythonhosted.org/packages/90/05/d4c6a778d7a7de0be366bc4a850b4ffaeac2abad927f95fa8ba6f355a082/TA-Lib-0.4.17.tar.gz
Collecting numpy (from TA-Lib)
  Using cached https://files.pythonhosted.org/packages/d2/ab/43e678759326f728de861edbef34b8e2ad1b1490505f20e0d1f0716c3bf4/numpy-1.17.4-cp36-cp36m-manylinux1_x86_64.whl
Building wheels for collected packages: TA-Lib
  Running setup.py bdist_wheel for TA-Lib ... done
  Stored in directory: /home/hellopython/.cache/pip/wheels/2a/2e/ec/71c565b2e0091e03a2b56abfbfd062f14a01a8d7b20ffe8bd5
Successfully built TA-Lib
Installing collected packages: numpy, TA-Lib
Successfully installed TA-Lib-0.4.17 numpy-1.17.4

hellopython@ubuntu:/usr/local/bin$ sudo apt-get install python3-pip python3-setuptools python3-dev python3-wheel
[sudo] password for hellopython: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3-setuptools is already the newest version (39.0.1-2).
python3-wheel is already the newest version (0.30.0-0.2).
python3-wheel set to manually installed.
python3-dev is already the newest version (3.6.7-1~18.04).
python3-pip is already the newest version (9.0.1-2.3~ubuntu1.18.04.1).
0 to upgrade, 0 to newly install, 0 to remove and 0 not to upgrade.
hellopython@ubuntu:/usr/local/bin$ pip install TA-Lib
Collecting TA-Lib
Collecting numpy (from TA-Lib)
  Using cached https://files.pythonhosted.org/packages/d2/ab/43e678759326f728de861edbef34b8e2ad1b1490505f20e0d1f0716c3bf4/numpy-1.17.4-cp36-cp36m-manylinux1_x86_64.whl
Installing collected packages: numpy, TA-Lib
Successfully installed TA-Lib-0.4.17 numpy-1.17.4

hellopython@ubuntu:~$ ls -a
Documents         .profile                         .virtualenvs
......
hellopython@ubuntu:~$ cd .virtualenvs/
hellopython@ubuntu:~/.virtualenvs$ ls
dm               postdeactivate    preactivate      prermvirtualenv
get_env_details  postmkproject     predeactivate
initialize       postmkvirtualenv  premkproject
postactivate     postrmvirtualenv  premkvirtualenv
hellopython@ubuntu:~/.virtualenvs$ source dm/bin/activate
(dm) hellopython@ubuntu:~/.virtualenvs/dm/bin$ pip3 install TA-Lib
Processing /home/hellopython/.cache/pip/wheels/2a/2e/ec/71c565b2e0091e03a2b56abfbfd062f14a01a8d7b20ffe8bd5/TA_Lib-0.4.17-cp36-cp36m-linux_x86_64.whl
Requirement already satisfied: numpy in /home/hellopython/.virtualenvs/dm/lib/python3.6/site-packages (from TA-Lib) (1.14.2)
Installing collected packages: TA-Lib
Successfully installed TA-Lib-0.4.17

我在物理机中安装了TA-Lib,所以dm虚拟机里pip3 install TA-Lib 就不需安装,引用就好,才可在pip3 freeze中看到TA-Lib。

(dm) hellopython@ubuntu:~/.virtualenvs$ pip3 freeze
TA-Lib==0.4.17
......

sudo pip install TA-Lib 相比 pip install TA-Lib是有root权限来安装的,即使报错也会忽略,直到安装成功,但是问题还在。我这系统默认用python2来安装TA-Lib。pip3就用python3解释器。

总结:该问题可能是因为缺少wheel,所以pip3 install wheel,再不行sudo apt-get install python3-pip python3-setuptools python3-dev python3-wheel,期间遇到的其它问题参考上面,建议用pip3 install xxx而先别sudo pip3 install xxx, 毕竟最好把问题都修复好才安装嘛,但是急用就选后者。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值