Having trouble solving the error modulenotfounderror: no module named ‘graphviz’ in Python? Don’t worry, as in this article we will show you how to fix this problem and give you a brief understanding of this error.
What does this error indicate? This error indicates that the graphviz module is not found in your system or Python environment.
When and why does this error occur? This error occurs when you try to import the graphviz module and it is not installed on your system or Python environment.
What is Python?
Python is one of the most popular programming languages. It is used for developing a wide range of applications. It is a high-level programming language that is usually used by developers nowadays due to its flexibility.
Returning to our issue, we must take a few actions to fix this error. So, without further ado, let’s move on to our “how to fix this error” tutorial.
How to solve “no module named ‘graphviz’” in Python
Resolving the error modulenotfounderror: no module named 'graphviz'
is an easy task. All you have to do is:
Install the graphviz module
To install this module, open your cmd or command prompt, then input the command.
pip install graphviz
The command pip install graphviz
will download and install the latest version of the graphviz module on your system.
Note: If the graphviz module is already installed in your system and this error occurred, follow the steps below.
- Check the path to the module. To do so, input the command
pip show graphviz
into your command prompt.
The commandpip show graphviz
will display information about your graphviz module, including its location. What you have to do is check if it is included in your system’s path variable.
- Add the module to your system’s path variable. If the graphviz module is not included in your system’s path variable, add it manually. To do so, input the command
export PATH=$PATH:/path/to/graphviz/
.
Note: With the real path to the graphviz module on your system, change the “/path/to/graphviz/”.
Installing the ‘graphviz’ module on different platforms
Anaconda: If you're using Anaconda, use the commandconda install -c anaconda graphviz
. Jupyter Notebook: If you're using Jupyter Notebook, use the command!pip install graphviz
. For Ubuntu 20.04.4 LTS: Use the commandsudo apt-get install graphviz
.
Commands you might need
pip list
This command will display all the packages installed on your system, including their versions.
If you’re using Jupyter Notebook, use the!pip list
command instead ofpip list
. However, if you’re using Anaconda, use the commandconda list
.
python -m
Include this command in yourpip install graphviz
command if you get an error message stating that “pip” cannot be found. (example:python -m pip install graphviz
)
However, if you’re using Python 3, use the commandpython3 -m pip install graphviz
instead ofpython -m pip install graphviz
.
pip install --upgrade pip
Use this command to upgrade the pip package manager to its newest version. If your pip is already in the latest version, this will come out: “Requirement already satisfied.”
pip install --upgrade graphviz
Use this command to upgrade your module to its latest version. If it is already the latest version, this will come out: “Requirement already satisfied.”
If you’re using Jupyter Notebook, use the command!pip install --upgrade graphviz
instead ofpip install --upgrade graphviz
.
Conclusion
In conclusion, the error modulenotfounderror: no module named ‘graphviz’ can be easily solved by installing the graphviz module in your system or Python environment.
By following the guide above, there’s no doubt that you’ll be able to resolve this error quickly.
We hope you’ve learned a lot from this. If you have any questions or suggestions, please leave a comment below, and for more Python tutorials, visit our website.
Thank you for reading!