In this article, we will show you how to solve modulenotfounderror: no module named ‘dns’ in Python.
This is an avoidable error that a developer may encounter while working with Python.
What is Python?
Python is a popular programming language that is commonly used by developers.
It is due to its flexibility and because it is a high-level, general-purpose programming language.
By using it, we can’t avoid encountering errors like this one.
This error indicates that the ‘dns’ module is not installed in your system or Python environment.
Tip: Before proceeding, you might want to check the version of your Python.
To do so, open your command prompt and input the following command:
python --version
Alternatively, you can just go to Windows Search and search for Python.
There, you’ll see what version of Python you have.
How to solve “no module named ‘dns’” in Python
Time needed: 2 minutes
The following are the steps on how to resolve the error message modulenotfounderror: no module named ‘dns’.
- Check if the ‘dns’ module is installed.
The first step is to check if the dns module is installed in your Python environment or system.
To check, open the cmd or command prompt, then type the command pip list.
The command pip list will show you the list of installed modules on your system.
Moving on, if the dns module is not found, move to the next step. - Install the ‘dns’ module.
If the dns module is not found in your Python environment or system, install it.
To install, input the command pip install dnspython.
The command pip install dnspython will download and install the dnspython package, including the dns module, on your system.
Note:
If the dns module is already installed, yet you still have the same error, try moving the DNS module to a location that is part of your Python search path.
To do that, move to the next step. - Find the dns module.
Find the location of the dns module on your system.
To do so, input the command pip show dnspython.
The command pip show dnspython will display the information of the dnspython package, including its location. - Move the dns module.
Move the dns module to a location that is part of your Python search path.
Note: After following the steps above, try running your program again.
Tip: If you’ve already installed a dns module in your system and you encounter this error, try to upgrade it as it may be an old version.
- To upgrade the dns module, input the following command:
pip install –upgrade dnspython
The command pip install –upgrade dnspython will upgrade the dns module to its latest version.
If your dns module is already in the latest version, this will come out: “Requirement already satisfied.”
Note: If you get an error message stating that “pip” cannot be found, use the command python -m.
It will look like this
python -m pip install dnspython
Other Commands
- To install the dnspython package when you are using Python 3, use the command:
pip3 install dnspython
- To install the dnspython package when you are using Jupyter Notebook, use the command:
!pip install dnspython
- To install the dnspython package when you are using py alias (Windows), use the command:
py -m pip install dsnpython
You might also want to see this:
Conclusion
In conclusion, the error modulenotfounderror: no module named ‘dns’ can be easily solved by checking if the dns module is installed in your Python environment and, if not, by installing it.
By following the guide above, there’s no doubt that you’ll be able to resolve this error quickly.
I think we are done with our tutorial, IT source coders!
We hope you’ve learned something from this.
Thank you for reading!