NameError: name 'sc' is not defined

When i am trying to run pyspark and importing text file i am facing below error
Traceback (most recent call last): File “”, line 1, in NameError: name ‘sc’ is not defined

error please help me

@pradeep0306 - Usually we will face this issue when the pyspark NOT launched successfully.

You can try below statement to create the SparkContext (Sc).

from pyspark import SparkContext, SparkConf
conf = SparkConf().setAppName(“pyspark”)
sc = SparkContext(conf=conf)

You need to scroll up and see if pyspark is launched successfully or not. At the beginning of the error stack you will get necessary information.