Python DNS 模块导入错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21641696/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 23:19:43  来源:igfitidea点击:

Python DNS module import error

pythonpython-2.7moduleresolver

提问by ayushmad

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 dns 模块。我试图在新的 Linux 安装上使用它,但该模块没有被加载。我尝试清理并安装,但安装似乎不起作用。

    $ 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

更新了 python 版本和 pip 版本命令的输出

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

注意:- 我在新机器上安装了防火墙。我不确定它是否应该影响导入。但我试过禁用它,但它似乎仍然不起作用。

采纳答案by DanGar

I ran into the same issue with dnspython.

我在使用 dnspython 时遇到了同样的问题。

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

我的解决方案是从他们的官方 GitHub 项目构建源代码。

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

这样做之后,我就可以导入dns模块了。

EDIT

编辑

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

pip install 似乎不适用于此模块。按照说明从源代码安装。

回答by scottsanchez

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

您使用的 pip 版本很可能没有安装到您使用的 python 版本。我有一个盒子,就是这种情况...

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

如果看起来 pip 与你的 python 不匹配,那么你可能有类似我在我的盒子上找到的多个版本的 python 和 pip 的东西......

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

只要我使用 /home/student/class/bin/pip (与我在那个盒子上的 python 版本匹配的 2.7),那么我的导入就可以正常工作。

You can also try installing pip from source: http://www.pip-installer.org/en/latest/installing.html

您也可以尝试从源安装 pip: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!

可能有更好的方法来做到这一点,我也在学习我的方法,但这就是我解决它的方式 - 希望它有所帮助!

回答by Prahalad Deshpande

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

我安装dnspython 1.11.1使用我的Ubuntu箱pip install dnspython。我能够毫无问题地导入 dns 模块

I am using Python 2.7.4 on an Ubuntu based server.

我在基于 Ubuntu 的服务器上使用 Python 2.7.4。

回答by CashWasabi

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

您还可以使用以下命令通过 pip 安装软件包:

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

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

回答by Thibault Richard

On Debian 7 Wheezy, I had to do:

在 Debian 7 Wheezy 上,我必须这样做:

pip install --upgrade dnspython

even if python-dns package was installed.

即使安装了 python-dns 包。

回答by BJ Beej

This issue can be generated by Symantec End Point Protection (SEP). And I suspect most EPP products could potentially impact your running of scripts.

此问题可能由 Symantec End Point Protection (SEP) 生成。而且我怀疑大多数 EPP 产品可能会影响您的脚本运行。

If SEP is disabled, the script will run instantly.

如果禁用 SEP,脚本将立即运行。

Therefore you may need to update the SEP policy to not block python scripts accessing stuff.

因此,您可能需要更新 SEP 策略以不阻止 Python 脚本访问内容。

回答by Fergus

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

我通过卸载然后使用 PIP 重新安装 dnspython 模块解决了这个问题。

$ pip uninstall dnspython

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

在 pycache 中的一长串文件之后,键入 y 继续卸载。完成后键入:

$ pip install dnspython

I then ran my script and the errors were resolved.

然后我运行我的脚本并解决了错误。

回答by John McCurdy

I installed DNSpython 2.0.0 from the github source, but running 'pip list' showed the old version of dnspython 1.2.0

我从 github 源安装了 DNSpython 2.0.0,但运行 'pip list' 显示旧版本的 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

它仅在我运行“pip uninstall dnspython”后才起作用,它删除了旧版本,只剩下 2.0.0,然后“import dns”运行顺利

回答by jhutar

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:

这里的一个可能原因可能是您的脚本有错误的shebang(因此它没有使用您的virtualenv 中的python)。我刚刚做了这个改变,它有效:

-#!/bin/python
+#!/usr/bin/env python

Or ignore shebang and just run the script with python in your venv:

或者忽略shebang并在你的venv中使用python运行脚本:

$ python your_script.py

回答by L3arn3D

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.

使用“import dns.resolver”时出现错误。我试过 dnspython、py3dns 但他们失败了。dns 不会安装。经过多次尝试后,我安装了 pubdns 模块,它解决了我的问题。