ImportError: cannot import name ‘_unicodefun’ from ‘click’

Are you getting the error “black importerror: cannot import name ‘_unicodefun’ from ‘click’“? Yes, you have come to the right place. Today in this tutorial, I will show you how to solve this error.

The error “ImportError: cannot import name ‘_unicodefun’ from ‘click’” occurs because the ‘black’ module imports ‘_unicodefun’ from the ‘click’ package. but the ‘_unicodefun’ was removed from the ‘click’ in version 8.1.0.

[Fixed] ImportError: cannot import name ‘_unicodefun’ from ‘click’

You can solve this error easily by just upgrading your ‘black‘ module. A fix was introduced in black version 22.3.0, so by upgrading to the latest version, you can get rid of this error.

ImportError: cannot import name '_unicodefun' from 'click'

You can upgrade your ‘black‘ module using these commands:

pip install black --upgrade
pip3 install black --upgrade

# If you don't have pip in PATH environment variable, use these commands
python -m pip install black --upgrade
python3 -m pip install black --upgrade

# py alias (Only works on Windows)
py -m pip install black --upgrade

# If you are Jupyter Notebook
!pip install black --upgrade

If you are still facing the error, alternatively, you can install version 22.3.0 of ‘black‘, and not the latest version.

[Fixed]: No module named ‘google.cloud’ in Python

pip install black==22.3.0
pip3 install black==22.3.0

# If you don't have pip in PATH environment variable, use these commands
python -m pip install black==22.3.0
python3 -m pip install black==22.3.0

# py alias (Only works on Windows)
py -m pip install black==22.3.0

# If you are Jupyter Notebook
!pip install black==22.3.0

If you use a requirements.txt file, you can update it with the following command. With this command, your requirements.txt will be updated automatically.

pip freeze > requirements.txt

If you run ‘black‘ via a ‘pre-commit‘ hook, make sure to update your version of the ‘black‘ module.

environment.yml

- repo: https://github.com/psf/black
  rev: 22.10.0
  hooks:
    - id: black

If you are still getting the error try to clean your ‘pre-commit‘ using these commands:

pre-commit clean
pre-commit autoupdate

[Alternative] ImportError: cannot import name ‘_unicodefun’ from ‘click’

An alternative solution is to install the ‘click‘ version 8.0.4, which is the last version that exports ‘_unicodefun‘.

pip install click==8.0.4
pip3 install click==8.0.4

# If you don't have pip in PATH environment variable, use these commands
python -m pip install click==8.0.4
python3 -m pip install click==8.0.4

# py alias (Only works on Windows)
py -m pip install click==8.0.4

# If you are Jupyter Notebook
!pip install click==8.0.4

Conclusion ImportError: cannot import name ‘_unicodefun’ from ‘click’

Programmers, we discussed how we can solve this error “ImportError: cannot import name ‘_unicodefun’ from ‘click’“. If you are still facing the error please let us know in the comments section. I would love to solve your python problems.

Leave a Reply