问题
I installed scapy via MacPorts as recommended here in the official scapy documentation: http://www.secdev.org/projects/scapy/doc/installation.html#mac-os-x
It works just fine when I run scapy from the command-line.
However now I can't seem to import scapy into the Python interpreter or in a python script, here's the error.
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
I have also tried with Python2.5, doesn't work either.
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
I think it has to do with the path somehow, but I don't know where to edit those on Mac, especially that I installed scapy from MacPorts.
回答1:
Macports installs everything to /opt/local
. So I bet if you run /opt/local/bin/python
, you'll be able to import scapy
.
If you need scapy
to be importable from the default Python installation, you'll need to install it into that Python installation (instead of the other, Macports, Python installation).
Relavent information from other answers:
- Running Macports Python #1.
- Running MacPorts Python #2.
来源:https://stackoverflow.com/questions/14820811/error-importing-scapy-into-python-interpreter-on-osx-macports-install