Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
salmanhiro opened this issue Nov 22, 2021 · 17 comments
Closed
Labels
C: crash Black is crashing C: dependencies S: awaiting response Waiting for futher information from OP T: bug Something isn't working

Comments

@salmanhiro
Copy link

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

@salmanhiro salmanhiro added the T: bug Something isn't working label Nov 22, 2021
@ichard26 ichard26 added C: crash Black is crashing C: dependencies S: awaiting response Waiting for futher information from OP labels Nov 22, 2021
@ichard26
Copy link
Collaborator

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.

@JelleZijlstra
Copy link
Collaborator

Looks like this is probably something to do with namespace packages (https://www.python.org/dev/peps/pep-0420/).

@arturomf94
Copy link

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)

@JelleZijlstra
Copy link
Collaborator

@arturomf94 you're using an old version of Black.

@pmolodo
Copy link

pmolodo commented Mar 29, 2022

"old" meaning more than 5 hours ago:

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

(For the curious, this is the PR: #2966)

@JelleZijlstra
Copy link
Collaborator

"old" meaning more than 5 hours ago:

No, much older than that.

@arturomf94
Copy link

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

@pmolodo
Copy link

pmolodo commented Mar 29, 2022

Hmm - ok, how old, then? I was just writing some workaround code which is checking the version of black a user is requesting and pinning the version of click if it's before 22.3.0. Which version should I be checking for?

@JelleZijlstra
Copy link
Collaborator

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

@dahluwalia-ag
Copy link

I'm also having this error using pre-commit. pre-commit is using verison "21.12b0" so I will try the latest....

black....................................................................Failed
- hook id: black
- exit code: 1

Traceback (most recent call last):
  File "/Users/daahluwa/.cache/pre-commit/repo6miac9jr/py_env-python3.7/bin/black", line 8, in <module>
    sys.exit(patched_main())
  File "/Users/daahluwa/.cache/pre-commit/repo6miac9jr/py_env-python3.7/lib/pyth
on3.7/site-packages/black/__init__.py", line 1372, in patched_main
    patch_click()
  File "/Users/daahluwa/.cache/pre-commit/repo6miac9jr/py_env-python3.7/lib/python3.7/site-packages/black/__init__.py", line 1358, in patch_click
    from click import _unicodefun
ImportError: cannot import name '_unicodefun' from 'click' (/Users/daahluwa/.cache/pre-commit/repo6miac9jr/py_env-python3.7/lib/python3.7/site-packages/click/__init__.py)

@dahluwalia-ag
Copy link

Changing to version 22.3.0 has solved the problem... thanks!

@arturomf94
Copy link

Pinned on 22.3.0 - works now 👍. Thanks @JelleZijlstra.

I think that change probably broke a lot of pipelines though :/

@flipbit03
Copy link

Just ran into the same issue on black via pre-commit. Moving to 22.3.0 fixed it. Thank goodness.

@JKCai
Copy link

JKCai commented Mar 29, 2022

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

@flipbit03
Copy link

This was exactly my impression @JKCai, I just found this issue and we live debugged it together ahaha! Thanks everyone o/

@JuanEscorcia
Copy link

thanks a lot! :D

@JelleZijlstra
Copy link
Collaborator

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.

sighingnow added a commit to sighingnow/GraphScope that referenced this issue Mar 29, 2022
See also: psf/black#2634

Signed-off-by: Tao He <linzhu.ht@alibaba-inc.com>
sighingnow added a commit to alibaba/GraphScope that referenced this issue Mar 29, 2022
* Upgrade the required black version.

See also: psf/black#2634

Signed-off-by: Tao He <linzhu.ht@alibaba-inc.com>
davebulaval added a commit to GRAAL-Research/deepparse that referenced this issue Apr 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: crash Black is crashing C: dependencies S: awaiting response Waiting for futher information from OP T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

9 participants