Spark Session Problem: Exception: Java gateway process exited before sending its port number

I try to start a session in Spark. I have downloaded Java Version as below:

java version "17" 2021-09-14 LTS
Java(TM) SE Runtime Environment (build 17+35-LTS-2724)
Java HotSpot(TM) 64-Bit Server VM (build 17+35-LTS-2724, mixed mode, sharing)

I have also installed Pyspark.

Python 3.8.5 (default, Sep  4 2020, 02:22:02) 
[Clang 10.0.0 ] :: Anaconda, Inc. on darwin

But when I try to start a session, I got Exception Error. Code:

#Creating a spark connection
from pyspark import SparkContext

sc = SparkContext(master = "local")

Error:

Exception: Java gateway process exited before sending its port number

Can you help please? Thanks in advance.

Answer

Your java version (17) is too high for spark. From Spark documentation

Spark runs on Java 8/11, Scala 2.12, Python 3.6+ and R 3.5+

So you need to decrease your Java to 11 or 8.