0

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

Erevos
  • 3
  • 1

1 Answers1

0

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.

Alez
  • 1,913
  • 3
  • 18
  • 22
  • What i am getting when running echo %JAVA_HOME% is: C:\Program Files\Java\jdk-20. when running java -version i am getting: Error: opening registry key 'Software\JavaSoft\Java Runtime Environment' Error: could not find java.dll Error: Could not find Java SE Runtime Environment. – Erevos May 07 '23 at 09:32
  • Amd java -version output? – Alez May 07 '23 at 09:35
  • just updated the previous comment. – Erevos May 07 '23 at 09:35
  • It seems you have issues with the java installation. Try to follow this link https://stackoverflow.com/questions/6362037/java-error-opening-registry-key – Alez May 07 '23 at 09:39
  • Thank you, i will now follow the instructions provided by the link you sent me. – Erevos May 07 '23 at 09:41
  • Marked as accepted as the problem bypassed and this is a new one. Kind regards. – Erevos May 07 '23 at 09:59