设备
- 操作系统:Win10
- 编辑器:VSCode
- 环境管理工具:Conda 24.7.1
- Python版本:3.9
问题描述
在Conda环境下安装依赖包时,项目使用了pre-commit
工具,但在执行commit
操作时出现以下报错:
[INFO] Installing environment for https://github.com/psf/black.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('C:\\Users\\...\\.cache\\pre-commit\\repo1iqbheha\\py_env-default\\Scripts\\python.EXE', '-mpip', 'install', '.')
return code: 1
stdout:
Processing c:\users\...\...\.cache\pre-commit\repo1iqbheha
Installing build dependencies: started
Installing build dependencies: finished with status 'error'
stderr:
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
推测
根据可能造成问题的原因依次检查:
1.conda版本过旧
(conda版本一开始是23年的,commit不了后更新到最新版本24.7.1,依旧不行)
2.使用pre-commit没有初始化
pre-commit install
(仍然失败)
3.缺少ssl配置或网络连接问题
(用脚本检查,若打印出 “SSL connection successful!" 以及状态码200,说明python环境支持SSL,并且能够通过https连接到网站。这里开了代理成功连接到了。)
4.使用的pip不正确
get-command pip
(使用的pip就是conda的pip,没有问题)
5.代理影响了commit
(不管开不开代理,或者切换节点,都报一样的错)
6.pre-commit版本太高
(下载依赖没有指定pre-commit的版本,下载的是3.8的版本,咨询师兄建议版本降到3.3.1。 重新下载并初始化后,仍然不行)
7.interpreter选择错误
使用的就是conda\envs\虚拟环境下的python(3.9.19),没有问题。
总结
所有可能性排查完都没有解决,推测是我的电脑配置问题。目前的解决方案是用docker重新测试一下。