Error Importing scapy into Python interpreter on OSX [MacPorts install]

北城以北 提交于 2020-01-07 04:28:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!