新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:python如何安裝py4j

Mac安裝:
pip 安裝
pip install py4j py4j.jar包路徑:/usr/share/py4j/py4j0.x.jar or /usr/local/share/py4j/py4j0.x.jar
conda 安裝(或者使用Anaconda-Navigator安裝)
conda install py4j py4j.jar包路徑:/anaconda3/share/py4j/py4j0.x.jar
使用:
1、java代碼
// 需要導(dǎo)入py4j.jar包
import py4j.GatewayServer;
import java.util.Random;
public class EntryPoint {
private static final Random random = new Random();
public int randInt() {
return random.nextInt();
}
public static void main(String[] args) {
EntryPoint app = new EntryPoint();
// py4j服務(wù)
GatewayServer gatewayServer = new GatewayServer(app);
gatewayServer.start();
System.out.println("Gateway Server Started");
}
}2、python代碼
from py4j.java_gateway import JavaGateway # 初始化 gateway = JavaGateway() def main(): # 調(diào)用Java-EntryPoint中的randInt函數(shù) a = gateway.entry_point.randInt() print(a) if __name__ == '__main__': main()
注意:
1.導(dǎo)入py4j.jar包
2.運行Java代碼
3.運行Python代碼(必須在2之后)
python學(xué)習(xí)網(wǎng),免費的在線學(xué)習(xí)python平臺,歡迎關(guān)注!
本文題目:創(chuàng)新互聯(lián)Python教程:python如何安裝py4j
本文地址:http://www.dlmjj.cn/article/dhecpdj.html


咨詢
建站咨詢
