Python DNS模块导入错误

ayu*_*mad 22 python module resolver python-2.7

我一直在使用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

更新了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)

非常感谢你的帮助.

注意: - 我在新机器上安装了防火墙.我不确定它是否会影响导入.但我试过禁用它仍然似乎没有工作.

Dan*_*Gar 29

我遇到了与dnspython相同的问题.

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

所以我的步骤是:

git clone https://github.com/rthalley/dnspython
cd dnspython/
python setup.py install
Run Code Online (Sandbox Code Playgroud)

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

编辑

看来pip安装对这个模块不起作用.如上所述从源安装.

  • 对于 Debian 中的 python3`sudo apt-get install python3-dnspython` (4认同)

小智 5

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

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


Fer*_*gus 5

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

$ pip uninstall dnspython
Run Code Online (Sandbox Code Playgroud)

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

$ pip install dnspython
Run Code Online (Sandbox Code Playgroud)

然后,我运行了脚本,错误得到解决。