Python DNS module import error

140,125

Solution 1

I ran into the same issue with dnspython.

My solution was to build the source from their official GitHub project.

So my steps were:

git clone https://github.com/rthalley/dnspython
cd dnspython/
python setup.py install

After doing this, I was able to import the dns module.

EDIT

It seems the pip install doesn't work for this module. Install from source as described.

Solution 2

I solved this by uninstalling and then re-installing the dnspython module with PIP.

$ pip uninstall dnspython

After the long list of files within pycache, type y to continue with the uninstall. After complete type:

$ pip install dnspython

I then ran my script and the errors were resolved.

Solution 3

You could also install the package with pip by using this command:

pip install git+https://github.com/rthalley/dnspython

Solution 4

I installed dnspython 1.11.1 on my Ubuntu box using pip install dnspython. I was able to import the dns module without any problems

I am using Python 2.7.4 on an Ubuntu based server.

Solution 5

On Debian 7 Wheezy, I had to do:

pip install --upgrade dnspython

even if python-dns package was installed.

Share:
140,125
ayushmad
Author by

ayushmad

Updated on December 17, 2021

Comments

  • ayushmad
    ayushmad over 2 years

    I have been using python dns module.I was trying to use it on a new Linux installation but the module is not getting loaded. I have tried to clean up and install but the installation does not seem to be working.

    
        $ python --version
        Python 2.7.3
        $ sudo pip install dnspython
        Downloading/unpacking dnspython
          Downloading dnspython-1.11.1.zip (220Kb): 220Kb downloaded
          Running setup.py egg_info for package dnspython
    
        Installing collected packages: dnspython
          Running setup.py install for dnspython
    
        Successfully installed dnspython
        Cleaning up...
        $ python
        Python 2.7.3 (default, Sep 26 2013, 20:03:06) 
        [GCC 4.6.3] on linux2
        Type "help", "copyright", "credits" or "license" for more information.
        >>> import dns
        Traceback (most recent call last):
          File "", line 1, in 
        ImportError: No module named dns
    
    

    Updated Output of python version and pip version command

    
        $ which python
        /usr/bin/python
        $ python --version
        Python 2.7.3
        $ pip --version
        pip 1.0 from /usr/lib/python2.7/dist-packages (python 2.7)
    
    

    Thanks a lot for your help.

    Note:- I have firewall installed on the new machine. I am not sure if it should effect the import. but i have tried disabling it and still it does not seem to work.