Despite its popularity and features, plotly is unavailable in the default Python installation. Hence, you will face the “ModuleNotFoundError: No Module named plotly” error when importing the module.
This tutorial will show you how to install the Plotly package in your Python environment and resolve the ModuleNotFoundError when importing it.
Step 1: Installing pip
As mentioned, Plotly does not come installed with the default Python installer. Hence, to get plotly running, we need to install it manually.
We can do this using the pip package manager. Depending on the system, pip may not be installed.
If you already have pip installed and running on your system, feel free to skip the second section of this guide.
On Debian and any Debian-based distributions, run the command as shown:
The command above will install pip for Python3 on your system. For example, if you are running Python 2. x, run the command as shown:
On CentOS and REHL, run the command:
Step 2: Install Plotly
Once you have pip installed on your system, we can import Plotly by running the command:
If you are running Python3, run the command:
The command above should download and install Plotly.
You can verify this by importing the package as shown:
Running the import statement above in the Python interpreter should run without errors.
You can check the version by running:
The code above should return the installed Plotly version.
Keep in mind that Plotly requires Pandas and NumPy installed on your system.
This article discussed how to solve the modulenotfounderror: no module named ‘mysqldb’ error in Python.