black: ImportError: cannot import name 'echo' from 'click' (unknown location)

I’m using Python 3.8.9 with conda environment and resulted in this problem

Traceback (most recent call last):
  File "/Users/mac/opt/anaconda3/bin/black", line 5, in <module>
    from black import patched_main
  File "/Users/mac/opt/anaconda3/lib/python3.8/site-packages/black/__init__.py", line 46, in <module>
    from black.concurrency import cancel, shutdown, maybe_install_uvloop
  File "/Users/mac/opt/anaconda3/lib/python3.8/site-packages/black/concurrency.py", line 6, in <module>
    from black.output import err
  File "/Users/mac/opt/anaconda3/lib/python3.8/site-packages/black/output.py", line 11, in <module>
    from click import echo, style
ImportError: cannot import name 'echo' from 'click' (unknown location)

I tried to installing click by pip install click but the problem still persists

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 17

Commits related to this issue

Most upvoted comments

Getting something similar in a GitHub Actions workflow running 3.7.12:

Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.7.12/x64/bin/black", line 8, in <module>
    sys.exit(patched_main())
  File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/black/__init__.py", line 6606, in patched_main
    patch_click()
  File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/black/__init__.py", line 6595, in patch_click
    from click import _unicodefun  # type: ignore
ImportError: cannot import name '_unicodefun' from 'click' (/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/click/__init__.py)

I don’t know how everyone ended up on this unrelated issue but glad it helped 😃 For the record, #2964 was where we tracked this bug.

“old” meaning more than 5 hours ago:

https://github.com/psf/black/releases/tag/22.3.0

(For the curious, this is the PR: https://github.com/psf/black/pull/2966)

thanks for the almost live chat and solution. Save me from troubleshooting my environment.

Any version before 22.3.0 will fail. I was just pointing out that @arturomf94 was running a much older version.

Tbf, I think I am using and older one! I believe it’s black==20.8b1.

Hello!

It’s almost impossible to diagnose the issue without more information as especially this is an issue with the click library. As far as I can tell the echo function has existed under the click namespace for years. What version of click are you running? You might also want to upgrade / force-reinstall click via --upgrade / --force-reinstall pip install flags.