pythonpython-3.xmacospipx

Installing black with pipx does not install the dependency aiohttp


I've installed pipx with brew and then black with 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

However, I keep getting an import error when running 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]`

How to fix this? Why is pipx not installing the required dependency aiohttp_cors?

Also, why does it use python 3.11.1 when my system python is 3.9.6

$ python3 --version                                
Python 3.9.6

Doing as advised by @KarlKnechtel below:

$ brew install python@3.10                                
...
==> Pouring python@3.10--3.10.9.arm64_monterey.bottle.tar.gz
...
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
...

I then get:

$ python3 --version                                      
Python 3.10.9

$brew list python python3
...
/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/python3
/opt/homebrew/Cellar/python@3.10/3.10.9/bin/python3.10
...

but still, when I install black it installs 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! ✨ 🌟 ✨

Solution

  • I solved it as in edit 1 but later you have to do according to this:

    pipx install "black[d]" --force
    

    but after that I got error:

    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)
    

    so I had to:

    curl -sSL https://install.python-poetry.org | python3 - --uninstall
    curl -sSL https://install.python-poetry.org | python3 -
    

    And now:

    poetry env use /opt/homebrew/Cellar/python@3.10/3.10.9/bin/python3.10 
    

    as 3.10 is required for aiohttp as mentioned by @KarlKnechel