ModuleNotFoundError: No module named ‘click’ in Python

To create a command line application, Python provides a module named “click”. It is a supporting library for the “Flask” web development framework. You can import the library in Python to access different features of the “click” module. The error “No module named click” occurs in Python when the module is imported without being installed in Python.

This post will provide you with a detailed guide on how to fix the “No module named click” error in Python using the following contents:

Let’s begin with the first reason.

Reason: ‘click’ Module Not Installed in Python

The primary reason for the “no module named click” error in a python program is when we import the “click” module without installing it in Python. The below snippet shows this error:

The above snippet verified that the “click” module is not found in Python.

Solution (For Windows): Install Python ‘click’ Module

To correct this error, you need to install the python “click” module. But before installing this module, you need the “pip” package manager in Python. To install the pip package manager on windows and Linux, you can follow this particular “Python Guide”. To install the pip package manager in Ubuntu 22.04, you can go through this “Installation Guide

Step 1: Open Command Prompt Terminal

After installing the pip, now open the cmd one more time as shown in the following snippet:

Step 2: Install ‘click’ Module Using pip

After opening cmd type the following pip command to install the “click” module in Python:

> pip install click

The above snippet shows that the “click” module has been downloaded and installed in Python successfully.

If you get any permission error while installing Python, then you can use the following command in cmd to install the “click” module:

> pip install click --user

Step 3: Verification of ‘click’ Module Installation

After successfully installing the “click” module, now we will verify the installation in Python using the following command:

> pip show click

The above snippet shows the name, version, and location of the “click” module that was installed in Python.

Install ‘click’ Module in Anaconda Environment

To install the “click” module in Anaconda; you can use the given below command in Python:

> conda install -c conda-forge click

Install ‘click’ Module in Jupyter NoteBook

To install the “click” module in Jupyter Notebook you can use the following command:

> !pip install click

Solution: Install ‘click’ Module in Python (For Linux)

The following pip command can be used in the terminal to install the “click” module in Python for Linux:

$ pip3 install click

We can also install the “click” module using Linux package manager such as “apt”. Type the given below command in the terminal to update and install the “click” module:

$ sudo apt update
$ sudo apt install python3-click

That’s how the ‘click’ module error can be fixed.

Conclusion

The “ModuleNotFoundError” invokes when we import the “click” module without installing it in Python. To rectify this error in Python for Windows, you can use the “pip” command, and for Linux, you can use the “pip” and “apt” commands. The click module installation commands for “Anaconda” and “Jupyter Notebook” are also provided in this Python guide. This Python article presented a detailed guide on resolving the “no module named click” error.