ndiff - PYTHONPATH环境变量

时间:2015-01-06 14:03:39

标签: python diff nmap

我有Ndiff的问题,我无法执行它。 (Nmap非常完美)

所以我尝试使用ndiff并收到此错误消息:

Could not import the ndiff module: 'No module named ndiff'.

I checked in these directories:

/usr/local/bin
/usr/local/bin
/usr/local/bin/ndiff
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC
/Library/Python/2.7/site-packages

If you installed Ndiff in another directory, you may have to add the
modules directory to the PYTHONPATH environment variable.

所以我搜索ndiff的路径并将其导出到PYTHONPATH。但它没有成功,我做错了什么?

which ndiff
/usr/local/bin/ndiff

我用自制软件重新安装ndiff和nmap,并且在我尝试执行此代码后知道我收到此消息

$ ndiff firstScan.xml secondScann.xml > diffScan

Traceback (most recent call last):
  File "/usr/local/bin/ndiff", line 84, in <module>
    sys.excepthook = ndiff.excepthook
AttributeError: 'module' object has no attribute 'excepthook'

2 个答案:

答案 0 :(得分:0)

您尝试运行/usr/local/bin/ndiff的命令是伪装的Python脚本(也就是说,它没有.py扩展名。)

在该脚本顶部的某处,它尝试导入ndiff模块本身:

import ndiff

,看到路径/usr/local/,可能安装在/usr/local/lib/python2.7/site-packages/(*)中。您需要将此路径添加到PYTHONPATH

export PYTHONPATH=${PYTHONPATH}:/usr/local/lib/python2.7/site-packages

现在,脚本可以拿起模块,并愉快地继续。

(*)它可能安装在其他地方,在这种情况下,您必须手动找到它。您可以尝试find /usr/local -name ndiff.py之类的内容来查看它的安装位置。


重新安装后的第二个错误可能是由当前工作目录中的某个位置松散ndiff.py引起的。在这种情况下,/usr/local/bin/ndiff会尝试导入该文件,并认为它是实际的ndiff模块。由于它不是,它会在尝试访问ndiff.excepthook之类的某些模块属性时失败,这些属性松散ndiff.py没有。删除松散的文件,你应该好好去。

答案 1 :(得分:0)

可能没有必要更改PYTHONPTH环境变量,会发生的情况是ndiff脚本指向错误的路径或指向错误/不存在的文件。 只需编辑位于/ usr / bin / ndiff中的ndiff脚本(作为二进制文件传递):

# sudo vi /usr/bin/ndiff

并找到该行:INSTALL_LIB =&#39; ...

它应该读取python site-packages目录的完整路径,例如: INSTALL_LIB =&#39; /usr/lib/python2.7/site-packages'

在那里寻找名为ndiff.py的文件:

# sudo find /usr/lib/python2.7/site-packages -name ndiff.py

如果没有,则必须创建并粘贴此处的所有内容:https://raw.githubusercontent.com/nmap/nmap/master/ndiff/ndiff.py

它应该都可以。