Python DNS module import error
Question:
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.
Answers:
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.
Very possible the version of pip you’re using isn’t installing to the version of python you’re using. I have a box where this is the case…
try:
which python
python --version
pip -V
If it looks like pip doesn’t match your python, then you probably have something like the multiple versions of python and pip I found on my box…
[root@sdpipeline student]# locate bin/pip
/home/student/class/bin/pip
/home/student/class/bin/pip-2.7
/usr/bin/pip
/usr/bin/pip-python
As long as I use /home/student/class/bin/pip (2.7 that matches my python version on that box), then my imports work fine.
You can also try installing pip from source: http://www.pip-installer.org/en/latest/installing.html
There’s probably a better way to do this, I’m still learning my way around too, but that’s how I solved it — hope it helps!
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.
You could also install the package with pip by using this command:
pip install git+https://github.com/rthalley/dnspython
On Debian 7 Wheezy, I had to do:
pip install --upgrade dnspython
even if python-dns package was installed.
This issue can be generated by Symantec End Point Protection (SEP).
And I suspect most EPP products could potentially impact your running of scripts.
If SEP is disabled, the script will run instantly.
Therefore you may need to update the SEP policy to not block python scripts accessing stuff.
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.
I installed DNSpython 2.0.0 from the github source, but running ‘pip list’ showed the old version of dnspython 1.2.0
It only worked after I ran ‘pip uninstall dnspython’ which removed the old version leaving just 2.0.0 and then ‘import dns’ ran smoothly
One possible reason here might be your script have wrong shebang (so it is not using python from your virtualenv). I just did this change and it works:
-#!/bin/python
+#!/usr/bin/env python
Or ignore shebang and just run the script with python in your venv:
$ python your_script.py
I was getting an error while using “import dns.resolver”. I tried dnspython, py3dns but they failed.
dns won’t install. after much hit and try I installed pubdns module and it solved my problem.
In my case, I hava writen the code in the file named “dns.py”, it’s conflict for the package, I have to rename the script filename.
I faced the same problem and solved this like i described below:
As You have downloaded and installed dnspython successfully so
- Enter into folder dnspython
- You will find dns directory, now copy it
- Then paste it to inside site-packages directory
That’s all. Now your problem will go
If dnspython isn’t installed you can install it this way :
- go to your python installation folder site-packages directory
- open cmd here and enter the command :
pip install dnspython
Now, dnspython will be installed successfully.
ok to resolve this First install dns for python by cmd using pip install dnspython
(if you use conda first type activate
and then you will go in base (in cmd) and then type above code)
it will install it in anaconda site package ,copy the location of that site package folder from cmd, and open it . Now copy all dns folders and paste them in python site package folder. it will resolve it .
actually the thing is our code is not able to find the specified package in pythonsite package bcz it is in anacondasite package. so you have to COPY IT (not cut).
I have faced similar issue when importing on mac.i have python 3.7.3 installed
Following steps helped me resolve it:
- pip3 uninstall dnspython
- sudo -H pip3 install dnspython
Import dns
Import dns.resolver
If you don’t have (or don’t want) pip
installed there is another way. You can to solve this is to install package with native OS package manager.
For example for Debian-based systems this would be command:
apt install python3-dnspython
The same thing has happened to me and it turns out that the .py file had the name dns (dns.py) and apparently it cannot have that name since it is the name of the package and it is a problem, so I recommend trying to change the name for example (dns_1.py) in case dns is named
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.
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.
Very possible the version of pip you’re using isn’t installing to the version of python you’re using. I have a box where this is the case…
try:
which python
python --version
pip -V
If it looks like pip doesn’t match your python, then you probably have something like the multiple versions of python and pip I found on my box…
[root@sdpipeline student]# locate bin/pip
/home/student/class/bin/pip
/home/student/class/bin/pip-2.7
/usr/bin/pip
/usr/bin/pip-python
As long as I use /home/student/class/bin/pip (2.7 that matches my python version on that box), then my imports work fine.
You can also try installing pip from source: http://www.pip-installer.org/en/latest/installing.html
There’s probably a better way to do this, I’m still learning my way around too, but that’s how I solved it — hope it helps!
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.
You could also install the package with pip by using this command:
pip install git+https://github.com/rthalley/dnspython
On Debian 7 Wheezy, I had to do:
pip install --upgrade dnspython
even if python-dns package was installed.
This issue can be generated by Symantec End Point Protection (SEP).
And I suspect most EPP products could potentially impact your running of scripts.
If SEP is disabled, the script will run instantly.
Therefore you may need to update the SEP policy to not block python scripts accessing stuff.
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.
I installed DNSpython 2.0.0 from the github source, but running ‘pip list’ showed the old version of dnspython 1.2.0
It only worked after I ran ‘pip uninstall dnspython’ which removed the old version leaving just 2.0.0 and then ‘import dns’ ran smoothly
One possible reason here might be your script have wrong shebang (so it is not using python from your virtualenv). I just did this change and it works:
-#!/bin/python
+#!/usr/bin/env python
Or ignore shebang and just run the script with python in your venv:
$ python your_script.py
I was getting an error while using “import dns.resolver”. I tried dnspython, py3dns but they failed.
dns won’t install. after much hit and try I installed pubdns module and it solved my problem.
In my case, I hava writen the code in the file named “dns.py”, it’s conflict for the package, I have to rename the script filename.
I faced the same problem and solved this like i described below:
As You have downloaded and installed dnspython successfully so
- Enter into folder dnspython
- You will find dns directory, now copy it
- Then paste it to inside site-packages directory
That’s all. Now your problem will go
If dnspython isn’t installed you can install it this way :
- go to your python installation folder site-packages directory
- open cmd here and enter the command :
pip install dnspython
Now, dnspython will be installed successfully.
ok to resolve this First install dns for python by cmd using pip install dnspython
(if you use conda first type activate
and then you will go in base (in cmd) and then type above code)
it will install it in anaconda site package ,copy the location of that site package folder from cmd, and open it . Now copy all dns folders and paste them in python site package folder. it will resolve it .
actually the thing is our code is not able to find the specified package in pythonsite package bcz it is in anacondasite package. so you have to COPY IT (not cut).
I have faced similar issue when importing on mac.i have python 3.7.3 installed
Following steps helped me resolve it:
- pip3 uninstall dnspython
- sudo -H pip3 install dnspython
Import dns
Import dns.resolver
If you don’t have (or don’t want) pip
installed there is another way. You can to solve this is to install package with native OS package manager.
For example for Debian-based systems this would be command:
apt install python3-dnspython
The same thing has happened to me and it turns out that the .py file had the name dns (dns.py) and apparently it cannot have that name since it is the name of the package and it is a problem, so I recommend trying to change the name for example (dns_1.py) in case dns is named