2010-06-10 4 views
3

현재 파이썬 비트 토 런트 추적기를 자이 썬 내부에서 실행하려고하는데이 문제가 발생했습니다. 트래커는 내 플랫폼 용으로 컴파일 된 PyCrypto 라이브러리를 사용하여 파이썬 경로에 추가했습니다. 내가 코드를 실행하려고 할 때, 그러나, 나는 다음과 같은 오류 얻을 :자이 썬에서 PyCrypto로 가져 오기 문제

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 

내가 라이브러리가 파이썬 경로에 있는지 확신하기 때문에 명령

import Crypto.Cipher 

작품을

from Crypto.Cipher import ARC4 
동안

않습니다. 내가 실행 자바 코드는 다음과 같습니다

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

모든 종류의 도움을 제공 할 수있는 사람에게 미리 감사드립니다.

답변

0

나는이 상황에 맞는 잘 모르겠지만, 일부 인터넷 검색이되었다 :

다른 그럼에도 불구하고

Jython cannot find your Java class, even though it exists in the class path. This shows up as "ImportError: cannot import name xxx" or "AttributeError: java package xxx' has no attribute 'yyy'"

This happens when Jython is installed as a Java extension (i.e. when jython.jar is installed in java\jre\lib\ext) and your classes are installed in the classpath.

The reason is Java extensions can only see other extensions, not other classes defined in the CLASSPATH or passed in to java using the --classpath option.

There are two ways to fix this:

1) Move your classes to the java\jre\lib\ext directory.

2) Remove jython.jar from the java\jre\lib\ext directory and put jython.jar in the CLASSPATH or use the java --classpath option.

(from the Jython-users mailing list)

그리고 또, 유사한 문제지만, (http://wiki.python.org/jython/JythonFaq/InstallingJython에서) :

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

+0

흥미 롭습니다. jython을 자바 확장으로 설치하지 않았습니다. 독립 실행 형 lib jar 파일을 생성하고 프로젝트에 추가했습니다. – Arg

4

pycrypto가 C 확장이며 Jython이이 확장에 대한 Java 래퍼없이 호출 할 수 없기 때문에 이러한 현상이 발생할 수 있습니다.

+0

흠, 다른 C 확장이 제대로 작동하는 것 같습니다. 또한 모듈 자체를 호출 할 수 있으며 함수를 호출하지 않습니다. – Arg

+0

확장은 무엇입니까? 어쩌면 ARC4가 확장이며 Crypto.Cipher는 순수한 파이썬에서 파이썬 래퍼 일뿐입니다. – Tarantula

관련 문제