Modulenotfounderror: no module named ‘dns’ [SOLVED]

In this Python tutorial, we will show you how to solve the error modulenotfounderror: no module named ‘dns’ in Python that you might have encountered or may encounter.

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: modulenotfounderror: no module named 'dns'.

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

The following are the steps on how to resolve the error message modulenotfounderror: no module named ‘dns’ in Python.

  1. 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.

    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.

  2. 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.

  3. Find the dns module.

    Find the location of the dns module on your system. To do so, input the command pip show dnspython.

    pip show dnspython

    The command pip show dnspython will display the information of the dnspython package, including its location.

  4. 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

  1. Use the command pip3 install dnspython to install the dnspython package when you are using Python 3.
  2. Use the command !pip install dnspython to install the dnspython package when you are using Jupyter Notebook.
  3. Use the command py -m pip install dsnpython to install the dnspython package when you are using py alias (Windows).


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.

We hope you’ve learned something 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!

Leave a Comment