在OSX中将scapy导入Python解释器时出错【MacPorts安装】

0 投票
1 回答
3079 浏览
提问于 2025-04-17 15:32

我按照官方的 scapy 文档推荐的方法,通过 MacPorts 安装了 scapy,链接在这里:http://www.secdev.org/projects/scapy/doc/installation.html#mac-os-x

在命令行中运行 scapy 一切都很正常。

但是现在我在 Python 解释器或者 Python 脚本中导入 scapy 时遇到了问题,出现了这个错误。

Python 2.7.3 (default, Jan 31 2013, 22:54:33) 
[GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import scapy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named scapy

我也试过用 Python2.5,但也不行。

Python 2.5.6 (r256:88840, Aug  5 2011, 03:29:42) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import scapy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named scapy

我觉得这可能和路径有关,但我不知道在 Mac 上该怎么修改这些路径,尤其是因为我是通过 MacPorts 安装的 scapy。

1 个回答

3

Macports会把所有东西安装到/opt/local这个地方。所以我敢打赌,如果你运行/opt/local/bin/python,你就能导入scapy这个库。

如果你想让scapy能在默认的Python安装中使用,你需要把它安装到那个默认的Python里,而不是Macports的Python里。

其他答案中的相关信息:

撰写回答