在 jython 中导入 python 模块

发布于 2024-09-09 11:27:38 字数 494 浏览 3 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

海的爱人是光 2024-09-16 11:27:38

您打印 sys.path 的操作是正确的。现在您应该转到 python shell,并执行以下操作:

$ python
>>> import scapy
>>> print scapy.__file__

这将显示 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:

$ python
>>> import scapy
>>> print scapy.__file__

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.

找回味觉 2024-09-16 11:27:38

您可以为 jython 执行 easy_install。

运行:

jython ez_setup.py 

http://peak.telecommunity.com/dist/ez_setup.py

然后您将在 jython/bin 下获得一个 easy_install 脚本
去那里

jython easy_install scapy

(或您需要的任何模块)

然后下次启动 jython 时您将能够导入它。

You can do the easy_install for jython.

Run:

jython ez_setup.py 

from http://peak.telecommunity.com/dist/ez_setup.py

Then you will get a easy_install script under your jython/bin
go there and

jython easy_install scapy

(or whatever module you need)

Then next time you startup jython you will be able to import it.

神经大条 2024-09-16 11:27:38

对阿玛拉答案的修改。他的代码对我不起作用,但我用类似的方法解决了它。这反而有效。

从此处下载 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.py

Then run jython ez_setup.py scapy.

Running it on any folder path doesn't matter

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文