Importerror: cannot import name ‘parametersource’ from ‘click.core’

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.

Common Causes of cannot import name ‘parametersource’ from ‘click.core’

Now we already the main cause of this error which is an outdated version, nevertheless…

Here are other reasons that can help you in troubleshooting the error.

  • The parametersource module was added in version 8.0 of the Click package. So, if you are using an older version of Click, you may encounter this error.

  • Besides that, if you have a module or package in your project that is named click, it can cause a name conflict with the actual click package.

  • Also if you have circular imports in your project it can cause the parametersource module to be imported before it is defined.

  • If you have a file in your project that is named click.py, it can prevent the actual click package from being imported correctly.

  • Finally, if the click package has some dependencies, such as colorama and typing_extensions this lead to incorrect import.

Importerror: cannot import name ‘parametersource’ from ‘click.core’ – Solutions

Now that we already the causes and how this error occurs, try the given solutions to fix the error.

Upgrade version of the black module

Since the common cause of the error is due to outdated version of the black module that has the click module as a dependency…

Therefore 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

📌# When using py alias (Windows)

py -m pip install black --upgrade

📌# When using Jupyter Notebook
!pip install black --upgrade

When the given command does not work, I suggest upgrading the 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

📌# In case you're using Jupyter Notebook

!pip install click --upgrade

Reinstall the black and click modules

When the error still continues try to uninstall and install again the black and click modules.

pip uninstall black click -y
pip3 uninstall black click -y

pip install black click
pip3 install black click

Meanwhile if none of this works, I suggest upgrading all the packages in the environment.

Upgrade all packages in your environment

This time using Python script is the easiest way to upgrade all outdated packages.

You can store the script in a Python file, for instance main.py, and run the file with Python main.py to upgrade all of the outdated packages.

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)

Meanwhile, you can use alternative commands in upgrading 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

Anyway here are the fixed errors that can help you in case you encounter these issues.

Conclusion

In conclusion, Importerror: cannot import name ‘parametersource’ from ‘click.core‘ occurs when we have an outdated version of the click module.

The most straightforward way to fix the error is to update the outdated version of click and black module.

I thank that’s all for this error. I hope this article has helped you fix it.

Until next time! 😊

Leave a Comment