[英]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.