[英]Install black with pipx not install dependencies aiohttp
在 MacOs 上我用 brew 安裝了 pipx:
brew install pipx
然后pipx install black
$ pipx list
venvs are in /Users/mc/.local/pipx/venvs
apps are exposed on your $PATH at /Users/mc/.local/bin
package black 22.12.0, installed using Python 3.11.1
- black
- blackd
但是,我一直缺少依賴項:
$ /Users/mc/.local/bin/blackd
Traceback (most recent call last):
File "/Users/mc/.local/bin/blackd", line 5, in <module>
from blackd import patched_main
File "/Users/mc/.local/pipx/venvs/black/lib/python3.11/site-packages/blackd/__init__.py", line 14, in <module>
raise ImportError(
ImportError: aiohttp dependency is not installed: No module named 'aiohttp'. Please re-install black with the '[d]' extra install to obtain aiohttp_cors: `pip install black[d]`
如何解決?
為什么pipx
在安裝black
時沒有解決這個依賴關系?
當我的系統 python 是3.9.6
時,為什么它使用一些(不知道安裝在哪里)python 3.11.1
$ python3 --version
Python 3.9.6
編輯
我按照@KarlKnechtel 的以下回答建議做了:
$ brew install python@3.10
==> Auto-updated Homebrew!
Updated 1 tap (romkatv/powerlevel10k).
You have 2 outdated formulae installed.
You can upgrade them with brew upgrade
or list them with brew outdated.
==> Fetching python@3.10
==> Downloading https://ghcr.io/v2/homebrew/core/python/3.10/manifests/3.10.9
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/python/3.10/blobs/sha256:a9b28161cec6e1a027f1eab7576af7
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:a9b28161cec6e1a027f
######################################################################## 100.0%
==> Pouring python@3.10--3.10.9.arm64_monterey.bottle.tar.gz
==> /opt/homebrew/Cellar/python@3.10/3.10.9/bin/python3.10 -m ensurepip
==> /opt/homebrew/Cellar/python@3.10/3.10.9/bin/python3.10 -m pip install -v --no-deps --no-index --upgr
==> Caveats
Python has been installed as
/opt/homebrew/bin/python3
Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
/opt/homebrew/opt/python@3.10/libexec/bin
You can install Python packages with
pip3 install <package>
They will install into the site-package directory
/opt/homebrew/lib/python3.10/site-packages
tkinter is no longer included with this formula, but it is available separately:
brew install python-tk@3.10
See: https://docs.brew.sh/Homebrew-and-Python
==> Summary
🍺 /opt/homebrew/Cellar/python@3.10/3.10.9: 3,110 files, 57.1MB
==> Running `brew cleanup python@3.10`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
所以我得到:
$ python3 --version
Python 3.10.9
$brew list python python3
/opt/homebrew/Cellar/python@3.10/3.10.9/bin/2to3
/opt/homebrew/Cellar/python@3.10/3.10.9/bin/2to3-3.10
/opt/homebrew/Cellar/python@3.10/3.10.9/bin/idle3
/opt/homebrew/Cellar/python@3.10/3.10.9/bin/idle3.10
/opt/homebrew/Cellar/python@3.10/3.10.9/bin/pip3
/opt/homebrew/Cellar/python@3.10/3.10.9/bin/pip3.10
/opt/homebrew/Cellar/python@3.10/3.10.9/bin/pydoc3
/opt/homebrew/Cellar/python@3.10/3.10.9/bin/pydoc3.10
/opt/homebrew/Cellar/python@3.10/3.10.9/bin/python3
/opt/homebrew/Cellar/python@3.10/3.10.9/bin/python3-config
/opt/homebrew/Cellar/python@3.10/3.10.9/bin/python3.10
/opt/homebrew/Cellar/python@3.10/3.10.9/bin/python3.10-config
/opt/homebrew/Cellar/python@3.10/3.10.9/bin/wheel3
/opt/homebrew/Cellar/python@3.10/3.10.9/bin/wheel3.10
/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/ (3055 files)
/opt/homebrew/Cellar/python@3.10/3.10.9/IDLE 3.app/Contents/ (8 files)
/opt/homebrew/Cellar/python@3.10/3.10.9/lib/pkgconfig/ (4 files)
/opt/homebrew/Cellar/python@3.10/3.10.9/libexec/bin/ (6 files)
/opt/homebrew/Cellar/python@3.10/3.10.9/libexec/wheel-0.38.4-py3-none-any.whl
/opt/homebrew/Cellar/python@3.10/3.10.9/Python Launcher 3.app/Contents/ (16 files)
/opt/homebrew/Cellar/python@3.10/3.10.9/share/man/ (2 files)
但當我安裝black
時,它仍然安裝 python 3.11
:
$pipx install black[d]
zsh: no matches found: black[d]
$pipx install black
installed package black 22.12.0, installed using Python 3.11.1
These apps are now globally available
- black
- blackd
done! ✨ 🌟 ✨
我在編輯 1 中解決了它,但后來你必須按照這個做:
pipx install "black[d]" --force
但在那之后我得到了錯誤:
dyld[56881]: Library not loaded: '/opt/homebrew/Cellar/python@3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/Python'
Referenced from: '/Users/mc/Library/Application Support/pypoetry/venv/bin/python'
Reason: tried: '/opt/homebrew/Cellar/python@3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/Python' (no such file), '/Library/Frameworks/Python.framework/Versions/3.9/Python' (no such file), '/System/Library/Frameworks/Python.framework/Versions/3.9/Python' (no such file)
所以我不得不:
curl -sSL https://install.python-poetry.org | python3 - --uninstall
curl -sSL https://install.python-poetry.org | python3 -
現在:
poetry env use /opt/homebrew/Cellar/python@3.10/3.10.9/bin/python3.10
正如aiohttp
所提到的,aiohttp 需要 3.10
當您使用pipx
而不是pip
安裝 package 時,它將:
pip
將 package 安裝到該虛擬環境中blackd
)將起作用,而無需先激活特定的虛擬環境。 這是它的明確目的(即,不只使用pip
的原因),因此使用了不同的 Python 而不是系統 Python。
要使用 Black 定義的blackd
入口點(啟動服務器),需要aiohttp
可選依賴項。 這必須在安裝時指定。 根據錯誤消息,對於pip
,這看起來像pip install black[d]
。
但是,從 Black 發行說明(從版本 22.8.0 開始;當前版本 22.12.0):
Python 現在支持 3.11,blackd 除外,因為aiohttp在發布時不支持 3.11 (#3234)
因此, pipx
將需要使用舊版本來創建虛擬環境。
來自pipx
文檔:
用於安裝 package 的默認 python 可執行文件通常是用於執行 pipx 的 python 並且可以通過設置環境變量
PIPX_DEFAULT_PYTHON
來覆蓋。
據推測, brew install pipx
將 pipx 安裝到不是系統pipx
的某些 3.11 安裝中。發生這種情況是因為您不打算將任何東西安裝到系統 Python中。 顧名思義,您的(操作系統)系統依賴於它,流氓 package 可能會以多種方式嚴重損害您的計算機。 (因此默認情況下,為什么pip
在其中不可用。)
你可以:
使用brew
安裝 3.10 或更早版本,然后安裝pipx
,然后繼續pipx install black[d]
。
使用venv
創建一個基於你的系統 Python (3.9) 的虛擬環境; 默認情況下,此venv
應自動包含pip
(由venv
下載並安裝)。 激活此虛擬環境,然后使用pip
在其中安裝pipx
,然后繼續pipx install black[d]
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.