Reading timeยท4 min
If you got the error "Cannot import name 'ParameterSource' from 'click.core'", click on the second subheading.
The "ImportError: cannot import name '_unicodefun' from 'click'" is caused
because the black
module imports _unicodefun
from the click
package which
was removed in click
version 8.1.0
.
To solve the error, upgrade your version of the black
module.
ImportError: cannot import name '_unicodefun' from 'click' (/home/borislav/Desktop/bobbyhadz_python/venv/lib/python3.11/site-packages/click/__init__.py)
black
moduleA fix was introduced in black
version 22.3.0
, so to solve the error run the
following command to upgrade black
.
pip install black click --upgrade pip3 install black click --upgrade # ๐๏ธ if you don't have pip in PATH environment variable python -m pip install black click --upgrade python3 -m pip install black click --upgrade # ๐๏ธ py alias (Windows) py -m pip install black click --upgrade # ๐๏ธ for Jupyter Notebook !pip install black click --upgrade
The commands update the black module to the latest version where the issue is fixed.
black
Alternatively, you can install version 22.3.0
of black
, and not the latest
version.
pip install black==22.3.0 pip3 install black==22.3.0 # ๐๏ธ if you don't have pip in PATH environment variable python -m pip install black==22.3.0 python3 -m pip install black==22.3.0 # ๐๏ธ py alias (Windows) py -m pip install black==22.3.0 # ๐๏ธ for Jupyter Notebook !pip install black==22.3.0
If you use a requirements.txt
file, you can update it with the following
command.
pip freeze > requirements.txt
The pip freeze command will
update the contents of your requirements.txt
file to reflect the latest
changes.
black
command in a pre-commit hookIf you run black
via a pre-commit
hook, make sure to update your version of
the black
module.
- repo: https://github.com/psf/black rev: 22.10.0 hooks: - id: black
If the suggestion didn't help, try clearing your cache by running the following commands.
pre-commit clean pre-commit autoupdate
black.yml
fileYou can also update your black.yml
file, if you have one, to use a more recent
version of the black
module.
black.yml - name: install black run: | pip install black==22.10.0 - name: run black run: | black . --check --line-length 80
click
module to 8.0.4
An alternative solution is to pin your
click version to 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 python -m pip install click==8.0.4 python3 -m pip install click==8.0.4 # ๐๏ธ py alias (Windows) py -m pip install click==8.0.4 # ๐๏ธ for Jupyter Notebook !pip install click==8.0.4
If none of the suggestions helped, try upgrading all packages in your environment.
The most straightforward way to upgrade all outdated packages is to use a Python script.
import pkg_resources from subprocess import call packages = [dist.project_name for dist in pkg_resources.working_set] call("pip install --upgrade " + ' '.join(packages), shell=True)
main.py
and run the file with python main.py
to upgrade all of the outdated packages.Here are alternative commands you can use to upgrade all outdated packages.
# ๐๏ธ macOS or Linux pip install -U `pip list --outdated | awk 'NR>2 {print $1}'` # ๐๏ธ Windows for /F "delims= " %i in ('pip list --outdated') do pip install -U %i
If you use a requirements.txt
file, you can update it with the following
command.
pip freeze > requirements.txt
The "ImportError: cannot import name 'ParameterSource' from 'click.core'"
occurs when we have an outdated version of the click
module.
To solve the error, upgrade your versions of the click
and black
modules.
ImportError: cannot import name 'ParameterSource' from 'click.core' (/home/borislav/Desktop/bobbyhadz_python/venv/lib/python3.11/site-packages/click/core.py)
black
moduleThe error is most commonly caused due to having an outdated version of the black module that has the click module as a dependency.
The first thing you should try is to upgrade your version of the black
module.
pip install black --upgrade pip3 install black --upgrade # ๐๏ธ if you don't have pip in PATH environment variable python -m pip install black --upgrade python3 -m pip install black --upgrade # ๐๏ธ py alias (Windows) py -m pip install black --upgrade # ๐๏ธ for Jupyter Notebook !pip install black --upgrade
If the suggestion didn't help, try upgrading your click
module as well.
pip install click --upgrade pip3 install click --upgrade # ๐๏ธ if you don't have pip in PATH environment variable python -m pip install click --upgrade python3 -m pip install click --upgrade # ๐๏ธ py alias (Windows) py -m pip install click --upgrade # ๐๏ธ for Jupyter Notebook !pip install click --upgrade
black
and click
modulesIf the error persists, try to uninstall the black
and click
modules and then
install them.
pip uninstall black click -y pip3 uninstall black click -y pip install black click pip3 install black click
If none of the suggestions helped, try to upgrade all packages in your environment.
The most straightforward way to upgrade all outdated packages is to use a Python script.
import pkg_resources from subprocess import call packages = [dist.project_name for dist in pkg_resources.working_set] call("pip install --upgrade " + ' '.join(packages), shell=True)
main.py
and run the file with python main.py
to upgrade all of the outdated packages.Here are alternative commands you can use to upgrade all outdated packages.
# ๐๏ธ macOS or Linux pip install -U `pip list --outdated | awk 'NR>2 {print $1}'` # ๐๏ธ Windows for /F "delims= " %i in ('pip list --outdated') do pip install -U %i
If you use a requirements.txt
file, you can update it with the following
command.
pip freeze > requirements.txt