您现在的位置是:课程教程文章
python 如何安装py4j
2023-12-18 20:43课程教程文章 人已围观
-
Python | pandas | 大数据分析零基础入门|小
Python | pandas | 大数据分析零基础入门|小... -
Python 基础实战课程(完整)【51Reboot】
Python 基础实战课程(完整)【51Reboot】需要获取免费学习资料及51Reboot教育全部公开课视频录播、资料、文档的同学,... -
python全栈开发/自动化测试公开课,测试人
python全栈开发/自动化测试公开课,测试人微信扫码 ①领取更多软件测试课程视频、软件、学习笔记、面试题、综合资料... -
Python全栈开发/爬虫/人工智能/机器学习
Python全栈开发/爬虫/人工智能/机器学习课程详情咨询、优惠券领取加学习顾问 李老师微信咨询:15210665015...
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代码
// 需要导入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服务 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(): # 调用Java-EntryPoint中的randInt函数 a = gateway.entry_point.randInt() print(a) if __name__ == '__main__': main()
注意:
1.导入py4j.jar包
2.运行Java代码
3.运行Python代码(必须在2之后)
python学习网,免费的在线学习python平台,欢迎关注!
课程教程:python 如何安装py4j上一篇:python总说的cd是什么
下一篇:没有了