Exception: Java gateway process exited before sending the driver its port number

最近在运行python程序时,出现Exception: Java gateway process exited before sending the driver its port number错误,可以说是费了一个晚上才弄好的,上网查资料,发现这类错误及解决方法很多,但是感觉都是分散的,最主要的是对于本人来说效果几乎没有,所以,就总结了一套流程:
首先下载安装jdk,和jre,我的是1.7.0_80版本然后配置环境变量:官网:
http://www.oracle.com/technetwork/java/javase/downloads/index.html
Exception: Java gateway process exited before sending the driver its port number_第1张图片
右键点击我的电脑,点击属性,进入此页面中
Exception: Java gateway process exited before sending the driver its port number_第2张图片
Exception: Java gateway process exited before sending the driver its port number_第3张图片
在用户变量和系统变量新建都可以,我的在用户变量中
Exception: Java gateway process exited before sending the driver its port number_第4张图片!
创建JAVA_HOME

在变量值中写入你安装的路径
Exception: Java gateway process exited before sending the driver its port number_第5张图片,在用户变量中如果有path,则在path中添加:
path = %JAVA_HOME%\bin,如果没有则创建,注意,JAVA_HOME和path在同一个变量中,也就是要么都在用户变量中,要么都在系统变量中。
看是否配置成功,打开cmd,输入java -versionException: Java gateway process exited before sending the driver its port number_第6张图片如出现和我一样的界面,则配置成功,当然不要高兴太早,后面还有呢,下面安装和解压spark:
这里是我已经下载好的
1、下载官网:http://spark.apache.org/
  spark-1.6.0-bin-hadoop2.4\python\lib下py4j-0.9-src以及pyspark压缩目录解压得到py4j和pyspark目录,
2、 pycharm中选中file菜单下setting子菜单

Exception: Java gateway process exited before sending the driver its port number_第7张图片
3、 setting中点击”add content root to the module”,在窗口设置python的lib目录” spark-1.6.0-bin-hadoop2.4\python\lib”!
Exception: Java gateway process exited before sending the driver its port number_第8张图片
4、添加完看看是否正确,在项目下lib是否存在
Exception: Java gateway process exited before sending the driver its port number_第9张图片
5、Enviroment Variables
这里写图片描述
what!!!发生了什么?
原来没有配置pycharm中的环境变量,我们继续上图:
Exception: Java gateway process exited before sending the driver its port number_第10张图片
在当前项目下配置环境变量
Exception: Java gateway process exited before sending the driver its port number_第11张图片
Exception: Java gateway process exited before sending the driver its port number_第12张图片
添加以下内容,点击OK
PYSPARK_PYTHON=D:\python3.5.4\python3.5
PYTHONUNBUFFERED=1
SPARK_HOME=E:\spark-1.6.0-bin-hadoop2.4
说明:
1、PYSPARK_PYTHON=添加的是你的python所在路径
2、PYTHONUNBUFFERED=1
3、SPARK_HOME=是解压spark-1.6.0-bin-hadoop2.4.tgz后文件所在的路径,
OK,此时你会见证奇迹的时刻到了,运行项目,运行成功,那就恭喜你,如果此时还会报错:Exception: Java gateway process exited before sending the driver its port number,关机重启电脑,本人就是属于后者,一切配置完成,还是报错,重启电脑就会OK!

你可能感兴趣的:(Exception: Java gateway process exited before sending the driver its port number)