python-Jython中的PyCrypto导入问题
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python-Jython中的PyCrypto导入问题,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2310字,纯文字阅读大概需要4分钟。
内容图文
![python-Jython中的PyCrypto导入问题](/upload/InfoBanner/zyjiaocheng/671/7d40e80121254161901e55be9bec1a0e.jpg)
我目前正在尝试让jython内部运行python bittorrent tracker,而我遇到了此问题:
跟踪器使用PyCrypto库,该库是我为自己的平台编译并添加到python路径中的.但是,当我尝试运行代码时,出现以下错误:
Exception in thread "MainThread" Traceback (most recent call last):
File "./python_dep/BitTorrent-5.2.2/bittorrent-tracker.py", line 21, in <module>
from BitTorrent.track import track
File "./python_dep/BitTorrent-5.2.2/BitTorrent/track.py", line 50, in <module>
from BitTorrent.UI import Size
File "./python_dep/BitTorrent-5.2.2/BitTorrent/UI.py", line 37, in <module>
from BitTorrent.MultiTorrent import UnknownInfohash, TorrentAlreadyInQueue, TorrentAlreadyRunning, TorrentNotRunning
File "./python_dep/BitTorrent-5.2.2/BitTorrent/MultiTorrent.py", line 25, in <module>
from BitTorrent.Torrent import Feedback, Torrent
File "./python_dep/BitTorrent-5.2.2/BitTorrent/Torrent.py", line 32, in <module>
from BitTorrent.ConnectionManager import ConnectionManager
File "./python_dep/BitTorrent-5.2.2/BitTorrent/ConnectionManager.py", line 22, in <module>
from BitTorrent.Connector import Connector
File "./python_dep/BitTorrent-5.2.2/BitTorrent/Connector.py", line 27, in <module>
from Crypto.Cipher import ARC4
ImportError: cannot import name ARC4
Java Result: 1
我很确定该库位于python路径中,因为命令
import Crypto.Cipher
工作,而
from Crypto.Cipher import ARC4
才不是.
我运行的Java代码如下所示:
package jythTest;
导入org.python.util.PythonInterpreter;
public class Main {
public static void main(String[] args) {
PythonInterpreter pythonInterpreter = new PythonInterpreter();
pythonInterpreter.exec("import sys");
pythonInterpreter.exec("sys.path.append(\"./python_dep/BitTorrent-5.2.2/\")");
pythonInterpreter.exec("sys.path.append(\"./python_dep/Twisted-10.0.0/\")");
pythonInterpreter.exec("sys.path.append(\"./python_dep/Zope-3.4.0/build/lib.linux-i686-2.6\")");
pythonInterpreter.exec("sys.path.append(\"./python_dep\")");
pythonInterpreter.exec("sys.path.append(\"./python_dep/pycrypto-2.0.1/build/lib.linux-i686-2.6\")");
pythonInterpreter.exec("sys.path.append(\"import Crypto.Cipher\")");
//pythonInterpreter.exec("print sys.path");
pythonInterpreter.execfile("./python_dep/BitTorrent-5.2.2/bittorrent-tracker.py");
}
}
在此先感谢任何可以提供任何帮助的人.
解决方法:
之所以发生这种情况,可能是因为pycrypto是C扩展,并且如果没有Java封装为此扩展,Jython将无法调用它.
内容总结
以上是互联网集市为您收集整理的python-Jython中的PyCrypto导入问题全部内容,希望文章能够帮你解决python-Jython中的PyCrypto导入问题所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。