[英]Unable to run pre-commit in anaconda environment
我當前的項目中有一個 Anaconda 環境。 我一直在嘗試配置我的預提交掛鈎,但是我一直遇到這個錯誤:
所以,當我第一次收到這個錯誤時,我做了一些研究,發現需要安裝ruamel.yaml
。 所以,我安裝了ruamel.yaml
並且確認安裝了最新版本:
但是,錯誤仍然存在。 我在該主題上看到的最相關的帖子似乎並沒有真正解決問題:
https://github.com/pre-commit/pre-commit-hooks/issues/353
我怎樣才能擺脫這個錯誤?
屏幕截圖很難看懂,但我認為這與 ruamel.yaml 沒有任何關系。 嘗試安裝其他一些 package 並且您可能會遇到相同的錯誤。
您應該確保安裝了較新的 3.8 版本,您的是 3.8.0,最新的是 3.8.11。 如果你的版本是從源代碼編譯的,它可能沒有在編譯期間安裝所有的庫。
在您的base
conda 環境而不是項目的 conda 環境中安裝和配置pre-commit
。
一年后我重現了這個錯誤,得到了一個相同的錯誤日志。
當我嘗試在 Windows 上激活的 Conda 環境中運行git commit
時發生了這種情況。雖然在那個 conda 環境中我能夠安裝軟件包,但pre-commit
安裝其掛鈎的機制最終被破壞,SSL 不可用並且相同問題中顯示的日志。
我的解決方法是停用我的 conda 環境,在我的base
conda 環境中安裝pre-commit
,並在激活base
的情況下進行一次提交。 出於某種原因,我仍然不明白,SSL 可用並且在pre-commit
從base
conda env 安裝其掛鈎時工作正常,但不是從激活的特定於項目的環境。
安裝和配置pre-commit
掛鈎后,我就可以激活項目的 conda 環境並從那里進行進一步的提交,因為pre-commit
重用了掛鈎的緩存安裝。
這是我機器上的錯誤日志,與我們在問題的屏幕截圖上看到的相同:
(my-conda-env) $ git commit
[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('C:\\Users\\someone\\.cache\\pre-commit\\repot4mg0fom\\py_env-default\\Scripts\\python.EXE', '-mpip', 'install', '.')
return code: 1
expected return code: 0
stdout:
Processing c:\users\someone\.cache\pre-commit\repot4mg0fom
Preparing metadata (setup.py): started
Preparing metadata (setup.py): finished with status 'done'
Could not fetch URL https://pypi.org/simple/ruamel-yaml/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/ruamel-yaml/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
stderr:
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/ruamel-yaml/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/ruamel-yaml/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/ruamel-yaml/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/ruamel-yaml/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/ruamel-yaml/
ERROR: Could not find a version that satisfies the requirement ruamel.yaml>=0.15 (from pre-commit-hooks) (from versions: none)
ERROR: No matching distribution found for ruamel.yaml>=0.15
Check the log at C:\Users\someone\.cache\pre-commit\pre-commit.log
運行conda deactivate
后:
(base) $ git commit
[INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
check yaml...........................................(no files to check)Skipped
check json...........................................(no files to check)Skipped
fix end of files.....................................(no files to check)Skipped
[... rest of my checks]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.