Import problem with PyCrypto in Jython

I'm currently trying to run the python bittorrent tracker inside jython, and I ran into this problem: the tracker uses the PyCrypto library, which I compiled for my platform and added python to the path. However, when I try to run the code, I get the following error:

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

I am sure the library is in the python path because the command

import Crypto.Cipher

works well

from Crypto.Cipher import ARC4

no. The java code that I run looks like this:

package jythTest;

import 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");
    }
}

Thanks in advance to anyone who could provide any assistance.

+3
source share
2 answers

, , , pycrypto C-, Jython Java .

+4

, , :

( http://wiki.python.org/jython/JythonFaq/InstallingJython)

Jython Java-, . "ImportError: xxx" "AttributeError: java package xxx" 'yyy' "

, Jython Java (.. jython.jar java\jre\lib\ext) .

Java- . , , CLASSPATH java, --classpath.

:

1) java\jre\lib\ext.

2) jython.jar java\jre\lib\ext jython.jar CLASSPATH java --classpath.

( Jython)

, :

( http://bugs.jython.org/issue1878866)

Linux jython 2.5. jython2.5.0/Lib/site-packages a foo, Java (Bar.class) jython (BarPy.py). __init__.py. jython Bar : " foo import Bar", BarPy. java , jython script

0

Source: https://habr.com/ru/post/1749460/


All Articles