title: Pycharm: Caused by: java.io.IOException: Cannot run program "python3.7": error=2, No such file or directory
body: <p>I've been using pycharm to edit python codes for quite sometime now but recently faced the following exception:</p>
  <pre><code>py4j.protocol.Py4JJavaError: An error occurred while calling z:org.apache.spark.api.python.PythonRDD.runJob.
  : org.apache.spark.SparkException: Job aborted due to stage failure: Task 0 in stage 2.0 failed 1 times, most recent failure: Lost task 0.0 in stage 2.0 (TID 2, localhost, executor driver): java.io.IOException: Cannot run program &quot;python3.7&quot;: error=2, No such file or directory
      at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
      at org.apache.spark.api.python.PythonWorkerFactory.startDaemon(PythonWorkerFactory.scala:197)
      at org.apache.spark.api.python.PythonWorkerFactory.createThroughDaemon(PythonWorkerFactory.scala:122)
      at org.apache.spark.api.python.PythonWorkerFactory.create(PythonWorkerFactory.scala:95)
      at org.apache.spark.SparkEnv.createPythonWorker(SparkEnv.scala:117)
      at org.apache.spark.api.python.BasePythonRunner.compute(PythonRunner.scala:109)
      at org.apache.spark.api.python.PythonRDD.compute(PythonRDD.scala:65)
      at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:346)
      at org.apache.spark.rdd.RDD.iterator(RDD.scala:310)
      at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:90)
      at org.apache.spark.scheduler.Task.run(Task.scala:123)
      at org.apache.spark.executor.Executor$TaskRunner$$anonfun$10.apply(Executor.scala:408)
      at org.apache.spark.util.Utils$.tryWithSafeFinally(Utils.scala:1360)
      at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:414)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at java.lang.Thread.run(Thread.java:748)
  Caused by: java.io.IOException: error=2, No such file or directory
      at java.lang.UNIXProcess.forkAndExec(Native Method)
      at java.lang.UNIXProcess.&lt;init&gt;(UNIXProcess.java:247)
      at java.lang.ProcessImpl.start(ProcessImpl.java:134)
      at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
      ... 16 more
  </code></pre>
  <p>Exception raises when I try the following:</p>
  <pre><code>    # Read data
      sample_path = 'path/to/file'
      sample_data = spark_sql_context.read.option(&quot;delimiter&quot;, &quot;\t&quot;).csv(sample_path, schema = INPUT_DF_SCHEMA)
      sample_data.show()
  
      # Select BPID
      sample_data = sample_data.select('idd')
      sample_data.show()
  
      # Convert to RDD
      sample_data_rdd = sample_data.rdd.map(list)
      print(sample_data_rdd.take(2))
  </code></pre>
  <p>What surprises me here is that the code was working just fine before and not sure why I'm seeing this right now. As suggested in other related topics/questions, I have made sure of the following:</p>
  <ul>
  <li>python 3.7 is installed</li>
  <li>path is added in the env</li>
  <li>in pycharm preferences, I have selected the relative path as for
  project interpreter</li>
  </ul>
  <p><a href="https://i.stack.imgur.com/AwEY9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AwEY9.png" alt="enter image description here" /></a></p>
  <p>And here is a snapshot of my <code>bash_profile</code>:</p>
  <pre><code>export PATH=$PATH:/usr/local/opt/python/libexec/bin 
  export PYSPARK_PYTHON=python3.7
  </code></pre>
  <p>Also when I type the following in command line:</p>
  <pre><code>/usr/local/opt/python/libexec/bin/python
  </code></pre>
  <p>I get the following:</p>
  <pre><code>Python 3.7.6 (default, Jan 31 2020, 15:07:01) 
  [Clang 9.0.0 (clang-900.0.38)] on darwin
  Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.
  &gt;&gt;&gt; 
  </code></pre>
  <p>Any reason why this might not be working?</p>
  <p>PS: I the following pythons installed on my mac it seems:</p>
  <p><a href="https://i.stack.imgur.com/JevXB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JevXB.png" alt="enter image description here" /></a></p>