Preview
Skip to content
CodingDiary
返回

解决 MacOS BigSur 使用 pip 安装依赖失败的问题

编辑页面
导读

被基金伤透了心,想学量化交易?安装聚宽数据 SDK 却报错 `clang: error: invalid version number in 'MACOSX_DEPLOYMENT_TARGET=11'`?这是 macOS Big Sur 的坑!Command Line Tools 版本太旧不支持 macOS 11。解决方法:用 `brew doctor` 检测问题,重装 CLT 升级 clang 到 12.0。附完整排查思路 + 解决步骤。

前言

年后到现在,我已经被基金伤透了心🤕

于是乎,为了争取不做 韭零后,我打算学习一下关于量化交易方面的内容。

学习量化交易,首先得先拿到交易的数据,这里我使用的是 聚宽数据 提供的本地数据接口,官方提供了 Python SDK,所以我就开始照着文档安装 SDK ……

照着文档的安装步骤,其实很简单:

$ pip install jqdatasdk

如果一切正常,那么你可以直接关掉本文了。

可如果你的环境和我一样:

那么很有可能会安装失败,并且错误日志如下(截取部分日志):

$ pip install jqdatasdk
Collecting jqdatasdk
  Using cached jqdatasdk-1.8.8-py3-none-any.whl (151 kB)
Requirement already satisfied: six in /usr/local/lib/python3.9/site-packages (from jqdatasdk) (1.15.0)
......(省略部分日志)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.9/site-packages (from requests->jqdatasdk) (1.26.3)
Building wheels for collected packages: thriftpy2
  Building wheel for thriftpy2 (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/local/opt/python@3.9/bin/python3.9 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/tx/_rv7b39127d289cpmm3dpylr0000gn/T/pip-install-p9oxcpjv/thriftpy2_42f75cad7b3842908525f1c376f2eb3d/setup.py'"'"'; __file__='"'"'/private/var/folders/tx/_rv7b39127d289cpmm3dpylr0000gn/T/pip-install-p9oxcpjv/thriftpy2_42f75cad7b3842908525f1c376f2eb3d/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 /private/var/folders/tx/_rv7b39127d289cpmm3dpylr0000gn/T/pip-wheel-vdjkejow
       cwd: /private/var/folders/tx/_rv7b39127d289cpmm3dpylr0000gn/T/pip-install-p9oxcpjv/thriftpy2_42f75cad7b3842908525f1c376f2eb3d/
  Complete output (93 lines):
  running bdist_wheel
  The [wheel] section is deprecated. Use [bdist_wheel] instead.
......(省略部分日志)
  creating build/temp.macosx-11-x86_64-3.9/thriftpy2/transport
  clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -I/usr/local/opt/openssl@1.1/include -I/usr/local/opt/sqlite/include -I/usr/local/opt/tcl-tk/include -I/usr/local/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/include/python3.9 -c thriftpy2/transport/cybase.c -o build/temp.macosx-11-x86_64-3.9/thriftpy2/transport/cybase.o
  clang: error: invalid version number in 'MACOSX_DEPLOYMENT_TARGET=11'
  error: command '/usr/bin/clang' failed with exit code 1
  ----------------------------------------

此时,我们可以发现日志里的关键信息:

clang: error: invalid version number in 'MACOSX_DEPLOYMENT_TARGET=11'

解决办法

1. 检查当前系统 clang 版本

$ clang --version
Apple clang version 11.0.3 (clang-1103.0.32.62)
Target: x86_64-apple-darwin20.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

2. 再次检查系统CommandLineTools版本

$ softwareupdate --all --install --force
Software Update Tool

Finding available software
No updates are available.

这里其实是个坑,通过 softwareupdate 其实发现不了,我们通过另外一个工具检查下

$ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!
......(省略部分日志)
Warning: Your Command Line Tools (CLT) does not support macOS 11.
It is either outdated or was modified.
Please update your Command Line Tools (CLT) or delete it if no updates are available.
Update them from Software Update in System Preferences or run:
  softwareupdate --all --install --force

If that doesn't show you any updates, run:
  sudo rm -rf /Library/Developer/CommandLineTools
  sudo xcode-select --install

Alternatively, manually download them from:
  https://developer.apple.com/download/more/.

华生你发现了一个盲点!果然,homebrew 真是好用!:full_moon_with_face:

Your Command Line Tools (CLT) does not support macOS 11.

3. 重新安装CommandLineTools

$ sudo rm -rf /Library/Developer/CommandLineTools
$ sudo xcode-select --install

根据网络环境,等待安装成功即可~

4. 再次检查 clang 版本

$ clang --version
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin20.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

5. 重新安装 SDK 试试?

$ pip install jqdatasdk
......(省略部分日志)
Successfully installed SQLAlchemy-1.3.23 jqdatasdk-1.8.8 msgpack-1.0.2 pandas-1.2.3 pymysql-1.0.2 requests-2.25.1 thriftpy2-0.4.14

Enjoy~

后记

测试一下,踏出第一步:

from jqdatasdk import *

auth('xxxxxx', 'xxxxxx')

# 查询 贵州茅台[600519.XSHG] 近5天的交易数据
df = get_price('600519.XSHG', count=5, end_date='2021-03-10', frequency='daily')
print(df)

此时得到如下结果:

提示:当前环境 pandas 版本高于 0.25,get_price 与 get_fundamentals_continuously 接口 panel 参数将固定为 False
注意:0.25 以上版本 pandas 不支持 panel,如使用该数据结构和相关函数请注意修改
auth success
               open    close     high      low     volume         money
2021-03-04  2095.00  2033.00  2096.00  2010.10  6508829.0  1.329730e+10
2021-03-05  2000.00  2060.11  2095.00  1988.00  6377920.0  1.310032e+10
2021-03-08  2074.96  1960.00  2085.00  1960.00  6309959.0  1.272425e+10
2021-03-09  1955.00  1936.99  2000.00  1900.18  8226581.0  1.610077e+10
2021-03-10  1977.00  1970.01  1999.87  1967.00  5117174.0  1.013691e+10

得到数据的同时,记得去专业的股票交易等网站去核对查询出来的数据是否准确哦~

因为这会直接影响到后面量化的指标!!

不玩了,把钱还我

参考

https://stackoverflow.com/questions/63972113/big-sur-clang-invalid-version-error-due-to-macosx-deployment-target


编辑页面
分享到:

上一篇
如何在本地快速启动一个 K8S 集群
下一篇
《每天5分钟玩转Kubernetes》之读书笔记