How to solve "Exception: Java gateway process exited before sending its port number"?

Viewed 416

I am trying to run pyspark in jupyter notebook. But, whenever I run the code it gets error "Exception: Java gateway process exited before sending its port number".

I also set my environment variable, but I believe that my mistake is in the setting. Here are variable name and value of 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 : notebook

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

Here is the code:

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()

Error:

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

Could you all please help me to solve this problem? I am thinking about system restore points but I'm afraid it will change ALL the systems. Btw, I'm using Windows 8

0 Answers
Related