spark-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andy Davidson <>
Subject ipython notebook NameError: name 'sc' is not defined
Date Tue, 03 Nov 2015 00:04:13 GMT

I recently installed a new cluster using the
spark-1.5.1-bin-hadoop2.6/ec2/spark-ec2. SparkPi sample app works correctly.

I am trying to run iPython notebook on my cluster master and use an ssh
tunnel so that I can work with the notebook in a browser running on my mac.
Bellow is how I set up the ssh tunnel

$ ssh -i $KEY_FILE -N -f -L localhost:8888:localhost:7000

$ ssh -i $KEY_FILE ec2-user@$SPARK_MASTER
$ cd top level notebook dir
$ IPYTHON_OPTS="notebook --no-browser --port=7000" /root/spark/bin/pyspark

I am able to access my notebooks in the browser by opening

When I run the following python code I get an error NameError: name 'sc' is
not defined? Any idea what the problem might be?

I looked through pyspark and tried various combinations of the following but
still get the same error

--no-browser --port=7000" /root/spark/bin/pyspark --master=local[2]

Kind regards


In [1]:
import sys
print (sys.version)
import os
print(os.getcwd() + "\n")
2.6.9 (unknown, Apr  1 2015, 18:16:00)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-16)]

In [2]:
from pyspark import SparkContext
textFile = sc.textFile("readme.txt")
NameError                                 Traceback (most recent call last)
<ipython-input-2-b67a9be29bd9> in <module>()
      1 from pyspark import SparkContext
----> 2 textFile = sc.textFile("readme.txt")
      3 textFile.take(1)

NameError: name 'sc' is not defined

In [ ]:

View raw message