windows下 python 使用 pip 安装TA-Lib报错的原因及解决方法
问题环境
Windows 10 x64 、python 3.8.6
问题描述
Windows 10 x64 下使用pip install ta-lib 命令安装ta-lib 库时会报错,错误信息为:talib/_ta_lib.c(680): fatal error C1083: 无法打开包括文件: “ta_libc.h”: No such file or directory .
安装过程日志如下:
(venv) F:\CodeProj>pip install ta-lib==0.4.24
Collecting ta-lib==0.4.24
Using cached TA-Lib-0.4.24.tar.gz (269 kB)
Preparing metadata (setup.py) ... done
Requirement already satisfied: numpy in f:\codeproj\venv\lib\site-packages (from ta-lib==0.4.24) (1.21.5)
Using legacy 'setup.py install' for ta-lib, since package 'wheel' is not installed.
Installing collected packages: ta-lib
Running setup.py install for ta-lib ... error
error: subprocess-exited-with-error
× Running setup.py install for ta-lib did not run successfully.
│ exit code: 1
╰─> [29 lines of output]
C:\Users\zhou\AppData\Local\Temp\pip-install-3z8q087g\ta-lib_61610fdfdd3848f58b5fb3d2ab780bf1\setup.py:77: UserWarning: Cannot find ta-lib library, installation may fa
il.
warnings.warn('Cannot find ta-lib library, installation may fail.')
running install
f:\codeproj\venv\lib\site-packages\setuptools\command\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other sta
ndards-based tools.
warnings.warn(
running build
running build_py
creating build
creating build\lib.win-amd64-cpython-38
creating build\lib.win-amd64-cpython-38\talib
copying talib\abstract.py -> build\lib.win-amd64-cpython-38\talib
copying talib\deprecated.py -> build\lib.win-amd64-cpython-38\talib
copying talib\stream.py -> build\lib.win-amd64-cpython-38\talib
copying talib\test_abstract.py -> build\lib.win-amd64-cpython-38\talib
copying talib\test_data.py -> build\lib.win-amd64-cpython-38\talib
copying talib\test_func.py -> build\lib.win-amd64-cpython-38\talib
copying talib\test_pandas.py -> build\lib.win-amd64-cpython-38\talib
copying talib\test_polars.py -> build\lib.win-amd64-cpython-38\talib
copying talib\test_stream.py -> build\lib.win-amd64-cpython-38\talib
copying talib\__init__.py -> build\lib.win-amd64-cpython-38\talib
running build_ext
building 'talib._ta_lib' extension
creating build\temp.win-amd64-cpython-38
creating build\temp.win-amd64-cpython-38\Release
creating build\temp.win-amd64-cpython-38\Release\talib
"D:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -Ic:\ta-lib\c\inc
lude -If:\codeproj\venv\lib\site-packages\numpy\core\include -If:\codeproj\venv\include "-ID:\Program Files\Python\Python38\include" "-ID:\Program Files\Python\Pyt
hon38\Include" "-ID:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\ATLMFC\include" "-ID:\Program Files (x86)\Microsoft Visual Studio\
2017\Enterprise\VC\Tools\MSVC\14.16.27023\include" "-ID:\Windows Kits\10\include\10.0.17763.0\ucrt" "-ID:\Windows Kits\10\include\10.0.17763.0\shared" "-ID:\Windows Kits\10\
include\10.0.17763.0\um" "-ID:\Windows Kits\10\include\10.0.17763.0\winrt" "-ID:\Windows Kits\10\include\10.0.17763.0\cppwinrt" /Tctalib/_ta_lib.c /Fobuild\temp.win-amd64-cp
ython-38\Release\talib/_ta_lib.obj
_ta_lib.c
talib/_ta_lib.c(680): fatal error C1083: 无法打开包括文件: “ta_libc.h”: No such file or directory
error: command 'D:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure
× Encountered error while trying to install package.
╰─> ta-lib
note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.
(venv) F:\CodePro>
问题原因 & 解决办法
-
不能直接pip下载。下载的是tar.gz的文件。windows不能解压运行。看了下清华的地址列表。只有tar.gz的和一个压缩包。其他地址没看。 直接下载压缩包文件。在使用python setup.py install的时候会使用到c++。然后又是一堆缺少dll的麻烦。dll补全以后又不能调用。。。 -
在 https://www.lfd.uci.edu/~gohlke/pythonlibs/ 找到ta-lib库。下载对应的版本的whl文件。 比如:TA_Lib-0.4.24-cp38-cp38-win_amd64.whl (前面是库版本,后面是对应的python版本。最后的数字代表windows系统。32位或者64位。电脑属性查看或者cmd里python查看) -
一定要一一对应。否则会报ERROR: TA_Lib-0.4.24-cp38-cp38-win32.whl is not a supported wheel on this platform. 平台不符合的错误。 -
下载出来的文件不能改名。否则会报ERROR: TA_Lib64.whl(你更改后的文件名) is not a valid wheel filename. 文件名无效错误。
另外,若想将TA-Lib包安装在python全局系统环境,则还要确保以下两项:
- 确保pip添加到windows环境变量。在哪都能使pip。
- 确保以上都满足cmd进入下载文件的位置。
TA_Lib-0.4.24-cp38-cp38-win_amd64.whl 下载页面
安装过程日志如下:(此处我直接将TA_Lib-0.4.24-cp38-cp38-win_amd64.whl 文件下载至 F:\CodeProj 目录)
(venv) F:\CodeProj>pip install TA_Lib-0.4.24-cp38-cp38-win_amd64.whl
Processing f:\codeproj\ta_lib-0.4.24-cp38-cp38-win_amd64.whl
Requirement already satisfied: numpy in f:\codeproj\venv\lib\site-packages (from TA-Lib==0.4.24) (1.21.5)
Installing collected packages: TA-Lib
Successfully installed TA-Lib-0.4.24
(venv) F:\CodeProj>
|