Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix spark-shell on Windows (fails with "was unexpected at this time")? [closed]

Tags:

apache-spark

I am getting following error when running spark-shell command:

enter image description here

I have downloaded spark-2.1.1-bin-hadoop2.7.tgz file from http://spark.apache.org/downloads.html, extracted the tar file and pasted the contents of the folder into c:\Spark directory.

After that I have configured the environment variable for spark and jdk accordingly, but I am getting this error.

like image 657
a3765910 Avatar asked May 17 '17 14:05

a3765910


People also ask

How do I activate my spark shell?

Launch Spark Shell (spark-shell) CommandGo to the Apache Spark Installation directory from the command line and type bin/spark-shell and press enter, this launches Spark shell and gives you a scala prompt to interact with Spark in scala language.

How do you close a spark shell?

Using Spark shell To close Spark shell, you press Ctrl+D or type in :q (or any subset of :quit ).

How do I set environment variables in Windows 10 spark?

Set SCALA_HOME in Control Panel\System and Security\System goto "Adv System settings" and add %SCALA_HOME%\bin in PATH variable in environment variables. Install Python 2.6 or later from Python Download link. Download SBT. Install it and set SBT_HOME as an environment variable with value as <<SBT PATH>> .


3 Answers

I resolved this error by using a short hand like "Progra~1" which is a short hand for "Program Files (x86)".

C:\Progra~1\Java\jdk1.8.0_161

like image 171
Kaushik Ghosh Avatar answered Oct 11 '22 13:10

Kaushik Ghosh


I'm almost sure that your JAVA_HOME environment variable contains a space that breaks spark-shell. Please re-install Java to a directory with no spaces in the path.


You can see the relevant piece of code in bin/spark-class2.cmd that spark-shell executes on Windows under the covers (through bin/spark-submit2.cmd shell script):

if "x%1"=="x" (

So when spark-class2.cmd substitutes %1 to a path with a space (or something similar) it ends up as:

if "x"Files\Java\jdk1.8.0_45""=="x" (

that gives the error due to too many double quotes.

The mystery is how does the JAVA_HOME end up in this place. I can't seem to find the reason, but that's what we see here.

like image 15
Jacek Laskowski Avatar answered Oct 11 '22 13:10

Jacek Laskowski


You can see this issue when your Java home set like following in windows

JAVA_HOME=C:\Program Files (x86)\Java\jdk1.8.0_162\bin

Issue here is space in "Program Files (x86)" If you add double quotes will not work on window 10

"C:\Program Files (x86)\Java\jdk1.8.0_162\bin" 

You need to copy Java into outside Program Files (x86) then it should work

JAVA_HOME=C:\java\jdk1.8.0_171\bin
like image 6
vaquar khan Avatar answered Oct 11 '22 13:10

vaquar khan