py4j调用java的问题。

丁杨帆 发布于 2011/09/21 13:26
阅读 2K+
收藏 0
关于它,为什么我不可以运行呢。py4j0.7.jar是干嘛用的?
加载中
0
无鸯
无鸯
老兄,你都不知道它是干吗用的,为什么会想着用它呢?
0
丁杨帆
丁杨帆

因为我按照文件上的操作,结果py4j我还是用不了,你能不能帮帮我。

from py4j.java_gateway import JavaGateway,java_import
gateway = JavaGateway()      # connect to the JVM


java_import(gateway.jvm, 'java.io.*')

这是错误代码

C:\Python32\python.exe D:/idepath/pythonpath/python/python3.2/re.py

Traceback (most recent call last):

  File "C:\Python32\lib\site-packages\py4j\java_gateway.py", line 211, in _get_connection

    connection = self.deque.pop()

IndexError: pop from an empty deque

 

During handling of the above exception, another exception occurred:

 

Traceback (most recent call last):

  File "D:/idepath/pythonpath/python/python3.2/re.py", line 5, in <module>

    java_import(gateway.jvm, 'java.io.*')

  File "C:\Python32\lib\site-packages\py4j\java_gateway.py", line 57, in java_import

    answer = gateway_client.send_command(command)

  File "C:\Python32\lib\site-packages\py4j\java_gateway.py", line 257, in send_command

    connection = self._get_connection()

  File "C:\Python32\lib\site-packages\py4j\java_gateway.py", line 213, in _get_connection

    connection = self._create_connection()

  File "C:\Python32\lib\site-packages\py4j\java_gateway.py", line 220, in _create_connection

    connection.start()

  File "C:\Python32\lib\site-packages\py4j\java_gateway.py", line 318, in start

    self.socket.connect((self.address, self.port))

socket.error: [Errno 10061] No connection could be made because the target machine actively refused it

 

Process finished with exit code 1

0
丁杨帆
丁杨帆

引用来自“无鸯”的答案

老兄,你都不知道它是干吗用的,为什么会想着用它呢?
from py4j.java_gateway import JavaGateway,java_import
gateway = JavaGateway()      # connect to the JVM


java_import(gateway.jvm, 'java.io.*') 
C:\Python32\python.exe D:/idepath/pythonpath/python/python3.2/re.py
Traceback (most recent call last):
  File "C:\Python32\lib\site-packages\py4j\java_gateway.py", line 211, in _get_connection
    connection = self.deque.pop()
IndexError: pop from an empty deque

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:/idepath/pythonpath/python/python3.2/re.py", line 5, in <module>
    java_import(gateway.jvm, 'java.io.*')
  File "C:\Python32\lib\site-packages\py4j\java_gateway.py", line 57, in java_import
    answer = gateway_client.send_command(command)
  File "C:\Python32\lib\site-packages\py4j\java_gateway.py", line 257, in send_command
    connection = self._get_connection()
  File "C:\Python32\lib\site-packages\py4j\java_gateway.py", line 213, in _get_connection
    connection = self._create_connection()
  File "C:\Python32\lib\site-packages\py4j\java_gateway.py", line 220, in _create_connection
    connection.start()
  File "C:\Python32\lib\site-packages\py4j\java_gateway.py", line 318, in start
    self.socket.connect((self.address, self.port))
socket.error: [Errno 10061] No connection could be made because the target machine actively refused it

0
Linius
Linius
你没在Java端开启GatewayServer吧?
返回顶部
顶部