运行python量化交易程序,报错说import Talib失败,库没有安装。
C:\Adevelop\stockphp\tdxanalysis>PYTHON -V
Python 3.11.4
看了下我的版本
C:\Adevelop\stockphp\tdxanalysis>pip install TA-Lib==0.4.0
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
ERROR: Could not find a version that satisfies the requirement TA-Lib==0.4.0 (from versions: 0.4.9, 0.4.14, 0.4.15, 0.4.16, 0.4.17, 0.4.18, 0.4.19, 0.4.20, 0.4.21, 0.4.22, 0.4.23, 0.4.24, 0.4.25, 0.4.26, 0.4.27, 0.4.28)
ERROR: No matching distribution found for TA-Lib==0.4.0
C:\hliu\Adevelop\stockphp\tdxanalysis>pip install TA-Lib==0.4.28
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting TA-Lib==0.4.28
Using cached https://pypi.tuna.tsinghua.edu.cn/packages/44/74/eddbc580f1486d55a831a04c2bd7e2e774a665e404f56d8ff30655f5cca6/TA-Lib-0.4.28.tar.gz (357 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 c:\hliu\anaconda3\lib\site-packages (from TA-Lib==0.4.28) (1.24.3)
Building wheels for collected packages: TA-Lib
Building wheel for TA-Lib (pyproject.toml) ... error
error: subprocess-exited-with-error
× Building wheel for TA-Lib (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [14 lines of output]
<string>:77: UserWarning: Cannot find ta-lib library, installation may fail.
running bdist_wheel
running build
running build_py
creating build
creating build\lib.win-amd64-cpython-311
creating build\lib.win-amd64-cpython-311\talib
copying talib\abstract.py -> build\lib.win-amd64-cpython-311\talib
copying talib\deprecated.py -> build\lib.win-amd64-cpython-311\talib
copying talib\stream.py -> build\lib.win-amd64-cpython-311\talib
copying talib\__init__.py -> build\lib.win-amd64-cpython-311\talib
running build_ext
building 'talib._ta_lib' extension
error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
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
报错说缺vc14.0,我看了一下,这玩意我电脑里面有的。
上网搜了一下,然后运行了这个
C:\Adevelop\stockphp\tdxanalysis>conda install -c conda-forge libta-lib
Collecting package metadata (current_repodata.json): | DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): conda.anaconda.org:443
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): mirrors.tuna.tsinghua.edu.cn:443
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): mirrors.tuna.tsinghua.edu.cn:443
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): mirrors.tuna.tsinghua.edu.cn:443
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): mirrors.tuna.tsinghua.edu.cn:443
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): mirrors.tuna.tsinghua.edu.cn:443
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): mirrors.tuna.tsinghua.edu.cn:443
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): conda.anaconda.org:443
/ DEBUG:urllib3.connectionpool:https://conda.anaconda.org:443 "GET /conda-forge/noarch/current_repodata.json HTTP/1.1" 200 None
/ DEBUG:urllib3.connectionpool:https://mirrors.tuna.tsinghua.edu.cn:443 "GET /anaconda/pkgs/main/win-64/current_repodata.json HTTP/1.1" 304 0
- DEBUG:urllib3.connectionpool:https://mirrors.tuna.tsinghua.edu.cn:443 "GET /anaconda/pkgs/r/noarch/current_repodata.json HTTP/1.1" 304 0
\ DEBUG:urllib3.connectionpool:https://mirrors.tuna.tsinghua.edu.cn:443 "GET /anaconda/pkgs/msys2/noarch/current_repodata.json HTTP/1.1" 304 0
\ DEBUG:urllib3.connectionpool:https://mirrors.tuna.tsinghua.edu.cn:443 "GET /anaconda/pkgs/r/win-64/current_repodata.json HTTP/1.1" 304 0
\ DEBUG:urllib3.connectionpool:https://mirrors.tuna.tsinghua.edu.cn:443 "GET /anaconda/pkgs/main/noarch/current_repodata.json HTTP/1.1" 304 0
/ DEBUG:urllib3.connectionpool:https://mirrors.tuna.tsinghua.edu.cn:443 "GET /anaconda/pkgs/msys2/win-64/current_repodata.json HTTP/1.1" 304 0
- DEBUG:urllib3.util.retry:Incremented Retry for (url='/conda-forge/win-64/current_repodata.json'): Retry(total=2, connect=None, read=None, redirect=None, status=None)
WARNING:urllib3.connectionpool:Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', TimeoutError('_ssl.c:985: The handshake operation timed out'))': /conda-forge/win-64/current_repodata.json
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (2): conda.anaconda.org:443
- DEBUG:urllib3.connectionpool:https://conda.anaconda.org:443 "GET /conda-forge/win-64/current_repodata.json HTTP/1.1" 200 None
done
Solving environment: /
The environment is inconsistent, please check the package plan carefully
The following packages are causing the inconsistency:
- https://repo.anaconda.com/pkgs/main/win-64::aiobotocore==2.4.2=py311haa95532_0
- https://repo.anaconda.com/pkgs/main/noarch::aioitertools==0.7.1=pyhd3eb1b0_0
- https://repo.anaconda.com/pkgs/main/win-64::anyio==3.5.0=py311haa95532_0
- https://repo.anaconda.com/pkgs/main/noarch::argon2-cffi==21.3.0=pyhd3eb1b0_0
- https://repo.anaconda.com/pkgs/main/win-64::holoviews==1.17.0=py311haa95532_0
- https://repo.anaconda.com/pkgs/main/win-64::hvplot==0.8.4=py311haa95532_0
- https://repo.anaconda.com/pkgs/main/win-64::jupyter==1.0.0=py311haa95532_8
- https://repo.anaconda.com/pkgs/main/win-64::jupyterlab==3.6.3=py311haa95532_0
- https://repo.anaconda.com/pkgs/main/win-64::jupyterlab_server==2.22.0=py311haa95532_0
- https://repo.anaconda.com/pkgs/main/win-64::jupyter_server==1.23.4=py311haa95532_0
- https://repo.anaconda.com/pkgs/main/win-64::jupyter_server_fileid==0.9.0=py311haa95532_0
- https://repo.anaconda.com/pkgs/main/win-64::jupyter_server_ydoc==0.8.0=py311haa95532_1
- https://repo.anaconda.com/pkgs/main/win-64::nbclassic==0.5.5=py311haa95532_0
- https://repo.anaconda.com/pkgs/main/win-64::notebook==6.5.4=py311haa95532_1
- https://repo.anaconda.com/pkgs/main/win-64::notebook-shim==0.2.2=py311haa95532_0
- https://repo.anaconda.com/pkgs/main/win-64::panel==1.2.1=py311haa95532_0
- https://repo.anaconda.com/pkgs/main/win-64::s3fs==2023.3.0=py311haa95532_0
- https://repo.anaconda.com/pkgs/main/win-64::scrapy==2.8.0=py311haa95532_0
- https://repo.anaconda.com/pkgs/main/win-64::twisted==22.10.0=py311h2bbff1b_0
- https://repo.anaconda.com/pkgs/main/win-64::typing-extensions==4.7.1=py311haa95532_0
- https://repo.anaconda.com/pkgs/main/win-64::_anaconda_depends==2023.07=py311_1
\
Warning: 2 possible package resolutions (only showing differing packages):
- https://repo.anaconda.com/pkgs/main/win-64::openssl-1.1.1w-h2bbff1b_0
- defaults/win-64::openssl-1.1.1w-h2bbff1bdone
## Package Plan ##
environment location: C:\hliu\anaconda3
added / updated specs:
- libta-lib
The following packages will be downloaded:
package | build
---------------------------|-----------------
ca-certificates-2024.2.2 | h56e8100_0 152 KB conda-forge
certifi-2024.2.2 | pyhd8ed1ab_0 157 KB conda-forge
libta-lib-0.4.0 | he774522_0 4.7 MB conda-forge
sniffio-1.3.1 | pyhd8ed1ab_0 15 KB conda-forge
typing-extensions-4.11.0 | hd8ed1ab_0 10 KB conda-forge
typing_extensions-4.11.0 | pyha770c72_0 37 KB conda-forge
------------------------------------------------------------
Total: 5.1 MB
The following NEW packages will be INSTALLED:
libta-lib conda-forge/win-64::libta-lib-0.4.0-he774522_0
sniffio conda-forge/noarch::sniffio-1.3.1-pyhd8ed1ab_0
typing_extensions conda-forge/noarch::typing_extensions-4.11.0-pyha770c72_0
The following packages will be UPDATED:
ca-certificates pkgs/main::ca-certificates-2023.08.22~ --> conda-forge::ca-certificates-2024.2.2-h56e8100_0
certifi pkgs/main/win-64::certifi-2023.7.22-p~ --> conda-forge/noarch::certifi-2024.2.2-pyhd8ed1ab_0
typing-extensions pkgs/main/win-64::typing-extensions-4~ --> conda-forge/noarch::typing-extensions-4.11.0-hd8ed1ab_0
Proceed ([y]/n)? y
Downloading and Extracting Packages
done
然后重新安装TALIB
C:\Adevelop\stockphp\tdxanalysis>pip install TA-Lib
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting TA-Lib
Using cached https://pypi.tuna.tsinghua.edu.cn/packages/44/74/eddbc580f1486d55a831a04c2bd7e2e774a665e404f56d8ff30655f5cca6/TA-Lib-0.4.28.tar.gz (357 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 c:\hliu\anaconda3\lib\site-packages (from TA-Lib) (1.24.3)
Building wheels for collected packages: TA-Lib
Building wheel for TA-Lib (pyproject.toml) ... error
error: subprocess-exited-with-error
× Building wheel for TA-Lib (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [14 lines of output]
<string>:77: UserWarning: Cannot find ta-lib library, installation may fail.
running bdist_wheel
running build
running build_py
creating build
creating build\lib.win-amd64-cpython-311
creating build\lib.win-amd64-cpython-311\talib
copying talib\abstract.py -> build\lib.win-amd64-cpython-311\talib
copying talib\deprecated.py -> build\lib.win-amd64-cpython-311\talib
copying talib\stream.py -> build\lib.win-amd64-cpython-311\talib
copying talib\__init__.py -> build\lib.win-amd64-cpython-311\talib
running build_ext
building 'talib._ta_lib' extension
error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
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
还是失败
然后到这里 Releases · cgohlke/talib-build · GitHub 下载了这个文件
C:\Adevelop\stockphp>pip install TA_Lib-0.4.28-cp311-cp311-win_amd64.whl
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Processing c:\hliu\adevelop\stockphp\ta_lib-0.4.28-cp311-cp311-win_amd64.whl
Requirement already satisfied: numpy in c:\hliu\anaconda3\lib\site-packages (from TA-Lib==0.4.28) (1.24.3)
Installing collected packages: TA-Lib
Successfully installed TA-Lib-0.4.28
C:\Adevelop\stockphp\tdxanalysis>python celue1.py
C:\Adevelop\stockphp\tdxanalysis\func_TDX.py:131: FutureWarning: iteritems is deprecated and will be removed in a future version. Use .items instead.
for k, v in series.iteritems():
C:\Adevelop\stockphp\tdxanalysis\celue1.py:167: FutureWarning: iteritems is deprecated and will be removed in a future version. Use .items instead.
for k, v in TJ06_MA60_DAY.iteritems():
Traceback (most recent call last):
之前的import Talib报错已经消失了,说明安装成功了。