在 jython 中导入 python 模块
我在 jython 下导入 scapy 时遇到一些问题。我一直在做java,但python只学了一两天。
重现该问题的简单情况是:
$jython
>>> import sys
>>> sys.path
['', '/usr/share/jython/Lib', '/usr/lib/site-python', '__classpath__']
>>> from scapy.all import *
Traceback (innermost last):
File "<console>", line 1, in ?
ImportError: no module named scapy
如果我在 python 下执行这些完全相同的步骤,一切都会正常。我如何告诉 jython 使用 scapy?如果有帮助,我正在运行 ubuntu 10.04 并通过 apt-get install 安装 jython 和 scapy
I'm having some issues importing scapy under jython. I've been doing java forever, but python for only a day or two.
The simple case to reproduce the problem is:
$jython
>>> import sys
>>> sys.path
['', '/usr/share/jython/Lib', '/usr/lib/site-python', '__classpath__']
>>> from scapy.all import *
Traceback (innermost last):
File "<console>", line 1, in ?
ImportError: no module named scapy
If I do these exact same steps under python
, everything works. How do I tell jython to use scapy? If it helps, I'm running ubuntu 10.04 and installed jython and scapy via apt-get install
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您打印 sys.path 的操作是正确的。现在您应该转到 python shell,并执行以下操作:
这将显示 scapy 的导入位置。最可能的问题是您的 jython sys.path 不包含包含 scapy 的目录。
You've done the right thing printing sys.path. Now you should go to your python shell, and do this:
This will show where scapy is being imported from. The most likely problem is that your jython sys.path doesn't include the directory containing scapy.
您可以为 jython 执行 easy_install。
运行:
从 http://peak.telecommunity.com/dist/ez_setup.py
然后您将在 jython/bin 下获得一个 easy_install 脚本
去那里
(或您需要的任何模块)
然后下次启动 jython 时您将能够导入它。
You can do the easy_install for jython.
Run:
from http://peak.telecommunity.com/dist/ez_setup.py
Then you will get a easy_install script under your jython/bin
go there and
(or whatever module you need)
Then next time you startup jython you will be able to import it.
对阿玛拉答案的修改。他的代码对我不起作用,但我用类似的方法解决了它。这反而有效。
从此处下载
ez_setup.py
http://peak.telecommunity.com/ dist/ez_setup.py然后运行
jython ez_setup.py scapy
。在任何文件夹路径上运行它并不重要
Modification from Amala's answer. His code doesn't work for me, but I solved it with something similar. This works instead.
Download
ez_setup.py
from here http://peak.telecommunity.com/dist/ez_setup.pyThen run
jython ez_setup.py scapy
.Running it on any folder path doesn't matter