title: Error while finding module specification for 'pyspark.worker' (ModuleNotFoundError: No module named 'pyspark')
body: <p>I'm trying to run a pyspark program, but I'm getting an error:</p>
  
  <blockquote>
    <p>python.exe: Error while finding module specification for
    'pyspark.worker' (ModuleNotFoundError: No module named 'pyspark')</p>
    
    <p>SparkException: Python worker failed to connect back.</p>
  </blockquote>
  
  <p>Code:</p>
  
  <pre><code>from pyspark.sql import SparkSession
  from pyspark.sql import Row
  import pyspark.sql.functions as func
  
  spark = SparkSession\
      .builder\
      .appName("ReplaceNanByAverage")\
      .config("spark.master", "local")\
      .getOrCreate()
  
  items = [(1,12),(1,float('Nan')),(1,14),(1,10),(2,22),(2,20),(2,float('Nan')),(3,300),
           (3,float('Nan'))]
  
  sc = spark.sparkContext
  rdd = sc.parallelize(items)
  itemsRdd = rdd.map(lambda x: Row(id=x[0], col1=int(x[1])))
  df = itemsRdd.toDF()
  </code></pre>
  
  <p>I've tried a lot of suggested solutions:</p>
  
  <ul>
  <li>Downgrading spark version</li>
  <li>Using findspark.init()</li>
  <li>Using findspark.init('/path/to/spark_home')</li>
  <li>Adding Content Root to the Project Structure.</li>
  <li>Using .config('PYTHONPATH','pyspark.zip:py4j-0.10.7-src.zip')</li>
  </ul>
  
  <p>But I keep getting the same error.</p>
  
  <p>I'm working in PyCharm IDE on Windows.</p>