如何解决“异常:Java网关进程在发送其端口号之前已退出”?

时间:2019-06-27 08:17:28

标签: java pyspark path

我正在尝试在jupyter笔记本中运行pyspark。但是,每当我运行代码时,都会收到错误消息“异常:发送网关的端口号之前,Java网关进程已退出。”

我还设置了环境变量,但是我认为我的错误在于设置。这是system的变量名称和值:

PATH:%USERPROFILE%\ AppData \ Local \ Microsoft \ WindowsApps; D:\ spark \ spark-2.2.1-bin-hadoop2.7 \ bin

HADOOP_HOME:D:\ spark \ spark-2.4.3-bin-hadoop2.7

JAVA_HOME:C:\ Program Files \ Java \ jdk-12.0.1

PYSPARK_DRIVER_PYTHON:jupyter

PYSPARK_DRIVER_PYTHON_OPTS:笔记本

SPARK_HOME:D:\ spark \ spark-2.4.3-bin-hadoop2.7

代码如下:

import findspark
findspark.init()

import pyspark # only run after findspark.init()
from pyspark.sql import SparkSession
spark = SparkSession.builder.getOrCreate()

df = spark.sql('''select 'spark' as hello ''')
df.show()

错误:

Exception                                 Traceback (most recent call last)
<ipython-input-4-84edcc0ab449> in <module>
      4 import pyspark # only run after findspark.init()
      5 from pyspark.sql import SparkSession
----> 6 spark = SparkSession.builder.getOrCreate()
      7 
      8 df = spark.sql('''select 'spark' as hello ''')

D:\spark\spark-2.4.3-bin-hadoop2.7\python\pyspark\sql\session.py in getOrCreate(self)
    171                     for key, value in self._options.items():
    172                         sparkConf.set(key, value)
--> 173                     sc = SparkContext.getOrCreate(sparkConf)
    174                     # This SparkContext may be an existing one.
    175                     for key, value in self._options.items():

D:\spark\spark-2.4.3-bin-hadoop2.7\python\pyspark\context.py in getOrCreate(cls, conf)
    365         with SparkContext._lock:
    366             if SparkContext._active_spark_context is None:
--> 367                 SparkContext(conf=conf or SparkConf())
    368             return SparkContext._active_spark_context
    369 

D:\spark\spark-2.4.3-bin-hadoop2.7\python\pyspark\context.py in __init__(self, master, appName, sparkHome, pyFiles, environment, batchSize, serializer, conf, gateway, jsc, profiler_cls)
    131                     " note this option will be removed in Spark 3.0")
    132 
--> 133         SparkContext._ensure_initialized(self, gateway=gateway, conf=conf)
    134         try:
    135             self._do_init(master, appName, sparkHome, pyFiles, environment, batchSize, serializer,

D:\spark\spark-2.4.3-bin-hadoop2.7\python\pyspark\context.py in _ensure_initialized(cls, instance, gateway, conf)
    314         with SparkContext._lock:
    315             if not SparkContext._gateway:
--> 316                 SparkContext._gateway = gateway or launch_gateway(conf)
    317                 SparkContext._jvm = SparkContext._gateway.jvm
    318 

D:\spark\spark-2.4.3-bin-hadoop2.7\python\pyspark\java_gateway.py in launch_gateway(conf)
     44     :return: a JVM gateway
     45     """
---> 46     return _launch_gateway(conf)
     47 
     48 

D:\spark\spark-2.4.3-bin-hadoop2.7\python\pyspark\java_gateway.py in _launch_gateway(conf, insecure)
    106 
    107             if not os.path.isfile(conn_info_file):
--> 108                 raise Exception("Java gateway process exited before sending its port number")
    109 
    110             with open(conn_info_file, "rb") as info:

Exception: Java gateway process exited before sending its port number

请大家帮我解决这个问题吗?我正在考虑系统还原点,但恐怕它将改变所有系统。顺便说一句,我正在使用Windows 8

0 个答案:

没有答案