RuntimeError: Java gateway process exited before sending its port number after setting JAVA_HOME

I’m trying to start pyspark using VSCode but i am getting the follow errors:

Java not found and JAVA_HOME environment variable is not set.
Install Java and set JAVA_HOME to point to the Java installation directory.
Traceback (most recent call last):
  File "c:\Users\Erevos\Desktop\Pyspark\LearnSpark.py", line 5, in <module>
    spark = SparkSession.builder.appName("MyApp").getOrCreate()
  File "C:\Users\Erevos\AppData\Local\Programs\Python\Python310\lib\site-packages\pyspark\sql\session.py", line 477, in getOrCreate
    sc = SparkContext.getOrCreate(sparkConf)
  File "C:\Users\Erevos\AppData\Local\Programs\Python\Python310\lib\site-packages\pyspark\context.py", line 512, in getOrCreate
    SparkContext(conf=conf or SparkConf())
  File "C:\Users\Erevos\AppData\Local\Programs\Python\Python310\lib\site-packages\pyspark\context.py", line 198, in __init__
    SparkContext._ensure_initialized(self, gateway=gateway, conf=conf)
  File "C:\Users\Erevos\AppData\Local\Programs\Python\Python310\lib\site-packages\pyspark\context.py", line 432, in _ensure_initialized
    SparkContext._gateway = gateway or launch_gateway(conf)
  File "C:\Users\Erevos\AppData\Local\Programs\Python\Python310\lib\site-packages\pyspark\java_gateway.py", line 106, in launch_gateway
    raise RuntimeError("Java gateway process exited before sending its port number")
RuntimeError: Java gateway process exited before sending its port number

i have already set the JAVA_HOME = path, here

Moreover, i have downloaded the folders required: here

>Solution :

Try to output the env variable

echo %JAVA_HOME%

and check if it’s correct.

If not correct check again your JAVA_HOME assignment.

Then, close and reopen the command prompt again that runs the java process (or the OS user session) and type java -version to check if it installed successfully.

If the java command fails follow this link.

Follow this link to have more info about JAVA_HOME.

Leave a Reply