构建ta-lib失败 ERROR: 无法为ta-lib构建wheels,这是安装基于pyproject.toml的项目所需的。

6
我正在安装ta-lib时遇到以下错误。我使用了以下命令:
!pip install ta-lib

请为我提供解决方案。
    Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/
Collecting ta-lib
  Using cached TA-Lib-0.4.25.tar.gz (271 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: numpy in /usr/local/lib/python3.8/dist-packages (from ta-lib) (1.21.6)
Building wheels for collected packages: ta-lib
  error: subprocess-exited-with-error
  
  × Building wheel for ta-lib (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> See above for output.
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  Building wheel for ta-lib (pyproject.toml) ... error
  ERROR: Failed building wheel for ta-lib
Failed to build ta-lib
ERROR: Could not build wheels for ta-lib, which is required to install pyproject.toml-based projects

我尝试了以下命令:

pip install --upgrade pip setuptools wheel

pip install pep517

!pip3 install --upgrade pip

!pip install pyproject-toml

pip install TA_Lib‑0.4.10‑cp35‑cp35m‑win_amd64.whl

!pip install ta-lib

我在安装gtar时遇到了同样的问题,建议安装Microsoft Visual C++ 14.0或更高版本。但即使安装了MVC++ 17.4.5,仍然无法正常工作。 - dudung
9个回答

11
在Anaconda命令提示符中键入以下命令(与此完全相同),这对我有用:
conda install -c conda-forge ta-lib

希望这也能节省他人的时间。


我之前遇到了以下问题: ERROR: Failed building wheel for Ta-lib Failed to build Ta-lib ERROR: Could not build wheels for Ta-lib, which is required to install pyproject.toml-based projects但是通过执行以下命令解决了这个问题: conda install -c conda-forge ta-lib请确保在conda终端中执行此命令。 - tonycor nikolauos
这个命令在我的 macOS 12.6.8 上有效。 - Brian

7
在Ubuntu 22.04中,我通过以下步骤解决了这个问题;(顺便提一下,在官方页面这里也提到了这个问题。)
  1. 下载ta-lib-0.4.0-src.tar.gz并将其放置在您打算安装talib的目录下,比如"~/talib",然后打开bash并跳转到刚才放置已下载文件的目录下:cd ~/talib
  2. tar -xzf ta-lib-0.4.0-src.tar.gz
  3. cd ta-lib/
  4. ./configure --prefix=/usr
  5. make
  6. sudo make install
  7. 将必要的目录添加到路径中。 为此,请编辑您主目录下的.bashrc文件,并添加以下行:请记住使用您的ta-lib路径更改PREFIX (~/talib/ta-lib/)

export TA_LIBRARY_PATH=$PREFIX/lib

export TA_INCLUDE_PATH=$PREFIX/include

  1. pip install TA-Lib
然后,TA-Lib将成功安装。祝您好运!

这个方法是可行的,但是在没有访问/usr目录或者尝试在某个环境中安装时需要注意一些问题。 - Daraan
这个方法是有效的,但是在没有访问/usr目录或者在某些环境中安装时需要注意一些问题。 - undefined

6

在Mac上通过终端解决:

$ brew install ta-lib

1
此错误是由于TA-Lib的wheel文件与您的系统不兼容所致。wheel文件是库的预构建版本,特定于某个Python版本和某个操作系统架构(例如Windows、Linux、macOS)。
以下是解决此错误的几种方法:
1. 确保在您的系统上安装了正确的Python版本。您正在尝试安装的TA-Lib wheel文件适用于Python 3.10,因此您需要安装该版本的Python才能使用它。
2. 检查您正在尝试安装的wheel文件是否适用于正确的架构(例如Windows 64位的win_amd64)。
3. 您可以尝试从源代码构建wheel文件。您可以尝试从TA-Lib网站下载源代码,然后尝试从源代码构建它。这将确保您拥有该版本Python和操作系统架构的wheel文件。
4. 或者,您可以尝试使用pip命令安装TA-Lib库而不使用wheel文件:pip install TA-Lib
5. 或者,您可以寻找另一个与您的系统架构和Python版本匹配的TA-Lib wheel文件。
通过尝试以上任何一种解决方案,您应该能够成功安装TA-Lib库。

1
解决方案是安装正确的版本:
cp310表示CPython 3.10(CPython是我们从python.org安装的基本Python)。
win_amd64表示可在64位系统上安装。
cp39表示可在CPython 3.9上安装。
等等...
请检查安装正确的版本。对我有用。

1

简短回答

构建 ta-lib python 包需要正确的编译器与您的系统匹配,因为 pip install 从不安装编译器

详细回答

我不确定是否相关,因为我在安装 gtar 时遇到类似的问题。我仅包含了相似的错误信息。

[..]
Building wheels for collected packages: gtar
  Building wheel for gtar (pyproject.toml) ... error
  error: subprocess-exited-with-error

× Building wheel for gtar (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [15 lines of output]
[..]
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for gtar
Failed to build gtar
ERROR: Could not build wheels for gtar, which is required to install pyproject.toml-based projects

安装了 Microsoft Visual C++ 14.0 或更高版本,正如建议的那样,在我的情况下是使用Desktop development with C++(包括 MVSC v143),使用 Visual Studio Build Tools 2022 -- 17.4.5,成功构建如下。
[..
Building wheels for collected packages: gtar
  Building wheel for gtar (pyproject.toml) ... done
  Created wheel for gtar: filename=gtar-1.1.3-cp310-cp310-win_amd64.whl size=618949 sha256=3179a7e8b5deb7e72f5722acc08fbecdfec6eeab88c4ac5778d3287a45635086
  Stored in directory: c:\users\full name\appdata\local\pip\cache\wheels\8a\10\b1\eddc3353608cbc386b0113f2bea34c83e5fae7ce26deb059db
Successfully built gtar
Installing collected packages: gtar
Successfully installed gtar-1.1.3

0

我尝试了这个 - 但是失败了,下面是错误信息,有什么建议吗?

!curl -L http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz -O && tar xzvf ta-lib-0.4.0-src.tar.gz !cd ta-lib && ./configure --prefix=/usr && make && make install && cd - && pip install ta-lib


ta-lib/src/tools/ta_regtest/ta_gDataLow.c
ta-lib/src/tools/Makefile.in
ta-lib/src/tools/Makefile.am
"ta-lib/src/tools/gen_code/
ta-lib/src/tools/gen_code/java/
ta-lib/src/tools/gen_code/java/PrettyCode.java
ta-lib/src/tools/gen_code/java/Main.java
ta-lib/src/tools/gen_code/gen_code.c
ta-lib/src/tools/gen_code/Makefile.in
ta-lib/src/tools/gen_code/Makefile.am
ta-lib/src/tools/gen_code/mcpp.exe
tar: !cd: Not found in archive
tar: Exiting with failure status due to previous errors"

> Blockquote

目前你的回答不够清晰,请编辑并添加更多细节,以帮助其他人理解它如何回答问题。你可以在帮助中心找到有关如何编写好答案的更多信息。 - Community

0

我在Mac Big Sur上遇到了问题,直到重新安装命令行工具并更新clang才解决了问题...

% sudo rm -rf /Library/Developer/CommandLineTools
% sudo xcode-select --install
% clang --version
Apple clang version 12.0.5 (clang-1205.0.22.11)

THEN...
$ pip3 install ta-lib
Collecting ta-lib
  Using cached TA-Lib-0.4.25.tar.gz (271 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: numpy in /usr/local/lib/python3.10/site-packages (from ta-lib) (1.24.0)
Building wheels for collected packages: ta-lib
  Building wheel for ta-lib (pyproject.toml) ... done
  Created wheel for ta-lib: filename=TA_Lib-0.4.25-cp310-cp310-macosx_11_0_x86_64.whl size=450718 sha256=d793bcd939d8b4c43efa00359ae45207e18d5d622a3d794f8da1fef12279d23b
  Stored in directory: /Users/xxxxxx/Library/Caches/pip/wheels/ac/12/d0/2ea05cfb5b9c4bbf47b45dd93ff5baed86ddb85c748166cb6f
Successfully built ta-lib
Installing collected packages: ta-lib
Successfully installed ta-lib-0.4.25

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接