title: Py4JJavaError: An error occurred while calling o37.showString. Spark & anaconda3
body: <p>I am a student I am really stuck with this problem of <strong>Py4JJavaError</strong> for two weeks, on the internet there is not much; I really need help:</p>
  
  <p>I follow this tutorial :<a href="https://docs.microsoft.com/fr-fr/azure/hdinsight/spark/apache-spark-machine-learning-mllib-ipython" rel="nofollow noreferrer"><code>https://docs.microsoft.com/fr-fr/azure/hdinsight/spark/apache-spark-machine-learning-mllib-ipython</code></a></p>
  
  <p>when I retrieve a line from the RDD in order to be able to observe the data schema like <code>inspections.take(1)</code> or <code>df.show(5)</code> I come across this error</p>
  
  <pre><code>&gt; Py4JJavaError                             Traceback (most recent call
  &gt; last) &lt;ipython-input-13-eb589bae8d4b&gt; in &lt;module&gt;()
  &gt; ----&gt; 1 df.show(5)
  &gt; 
  &gt; ~/anaconda3/lib/python3.6/site-packages/pyspark/sql/dataframe.py in
  &gt; show(self, n, truncate, vertical)
  &gt;     376         """
  &gt;     377         if isinstance(truncate, bool) and truncate:
  &gt; --&gt; 378             print(self._jdf.showString(n, 20, vertical))
  &gt;     379         else:
  &gt;     380             print(self._jdf.showString(n, int(truncate), vertical))
  &gt; 
  &gt; ~/anaconda3/lib/python3.6/site-packages/py4j/java_gateway.py in
  &gt; __call__(self, *args)    1255         answer = self.gateway_client.send_command(command)    1256         return_value
  &gt; = get_return_value(
  &gt; -&gt; 1257             answer, self.gateway_client, self.target_id, self.name)    1258     1259         for temp_arg in temp_args:
  &gt; 
  &gt; ~/anaconda3/lib/python3.6/site-packages/pyspark/sql/utils.py in
  &gt; deco(*a, **kw)
  &gt;      61     def deco(*a, **kw):
  &gt;      62         try:
  &gt; ---&gt; 63             return f(*a, **kw)
  &gt;      64         except py4j.protocol.Py4JJavaError as e:
  &gt;      65             s = e.java_exception.toString()
  &gt; 
  &gt; ~/anaconda3/lib/python3.6/site-packages/py4j/protocol.py in
  &gt; get_return_value(answer, gateway_client, target_id, name)
  &gt;     326                 raise Py4JJavaError(
  &gt;     327                     "An error occurred while calling {0}{1}{2}.\n".
  &gt; --&gt; 328                     format(target_id, ".", name), value)
  &gt;     329             else:
  &gt;     330                 raise Py4JError(
  &gt; 
  &gt; Py4JJavaError: An error occurred while calling o37.showString. :
  &gt; org.apache.spark.SparkException: Job aborted due to stage failure:
  &gt; Task 0 in stage 0.0 failed 1 times, most recent failure: Lost task 0.0
  &gt; in stage 0.0 (TID 0, localhost, executor driver):
  &gt; org.apache.spark.api.python.PythonException: Traceback (most recent
  &gt; call last):   File
  &gt; "/Users/sabbar/anaconda3/lib/python3.6/site-packages/pyspark/python/lib/pyspark.zip/pyspark/worker.py",
  &gt; line 372, in main
  &gt;     process()   File "/Users/sabbar/anaconda3/lib/python3.6/site-packages/pyspark/python/lib/pyspark.zip/pyspark/worker.py",
  &gt; line 367, in process
  &gt;     serializer.dump_stream(func(split_index, iterator), outfile)   File
  &gt; "/Users/sabbar/anaconda3/lib/python3.6/site-packages/pyspark/python/lib/pyspark.zip/pyspark/serializers.py",
  &gt; line 390, in dump_stream
  &gt;     vs = list(itertools.islice(iterator, batch))   File "/Users/sabbar/anaconda3/lib/python3.6/site-packages/pyspark/python/lib/pyspark.zip/pyspark/util.py",
  &gt; line 100, in wrapper
  &gt;     return f(*args, **kwargs)   File "&lt;ipython-input-10-9aa45565a8c1&gt;", line 3, in csvParse
  &gt; ModuleNotFoundError: No module named 'StringIO'
  &gt; 
  &gt;   at
  &gt; org.apache.spark.api.python.BasePythonRunner$ReaderIterator.handlePythonException(PythonRunner.scala:452)
  &gt;   at
  &gt; org.apache.spark.api.python.PythonRunner$$anon$1.read(PythonRunner.scala:588)
  &gt;   at
  &gt; org.apache.spark.api.python.PythonRunner$$anon$1.read(PythonRunner.scala:571)
  &gt;   at
  &gt; org.apache.spark.api.python.BasePythonRunner$ReaderIterator.hasNext(PythonRunner.scala:406)
  &gt;   at
  &gt; org.apache.spark.InterruptibleIterator.hasNext(InterruptibleIterator.scala:37)
  &gt;   at scala.collection.Iterator$$anon$12.hasNext(Iterator.scala:440)   at
  &gt; scala.collection.Iterator$$anon$11.hasNext(Iterator.scala:409)    at
  &gt; scala.collection.Iterator$$anon$11.hasNext(Iterator.scala:409)    at
  &gt; scala.collection.Iterator$$anon$11.hasNext(Iterator.scala:409)    at
  &gt; org.apache.spark.sql.catalyst.expressions.GeneratedClass$GeneratedIteratorForCodegenStage1.processNext(Unknown
  &gt; Source)   at
  &gt; org.apache.spark.sql.execution.BufferedRowIterator.hasNext(BufferedRowIterator.java:43)
  &gt;   at
  &gt; org.apache.spark.sql.execution.WholeStageCodegenExec$$anonfun$11$$anon$1.hasNext(WholeStageCodegenExec.scala:619)
  &gt;   at
  &gt; org.apache.spark.sql.execution.SparkPlan$$anonfun$2.apply(SparkPlan.scala:255)
  &gt;   at
  &gt; org.apache.spark.sql.execution.SparkPlan$$anonfun$2.apply(SparkPlan.scala:247)
  &gt;   at
  &gt; org.apache.spark.rdd.RDD$$anonfun$mapPartitionsInternal$1$$anonfun$apply$24.apply(RDD.scala:836)
  &gt;   at
  &gt; org.apache.spark.rdd.RDD$$anonfun$mapPartitionsInternal$1$$anonfun$apply$24.apply(RDD.scala:836)
  &gt;   at
  &gt; org.apache.spark.rdd.MapPartitionsRDD.compute(MapPartitionsRDD.scala:52)
  &gt;   at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:324)
  &gt;   at org.apache.spark.rdd.RDD.iterator(RDD.scala:288)     at
  &gt; org.apache.spark.rdd.MapPartitionsRDD.compute(MapPartitionsRDD.scala:52)
  &gt;   at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:324)
  &gt;   at org.apache.spark.rdd.RDD.iterator(RDD.scala:288)     at
  &gt; org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:90)    at
  &gt; org.apache.spark.scheduler.Task.run(Task.scala:121)   at
  &gt; org.apache.spark.executor.Executor$TaskRunner$$anonfun$10.apply(Executor.scala:402)
  &gt;   at org.apache.spark.util.Utils$.tryWithSafeFinally(Utils.scala:1360)
  &gt;   at
  &gt; org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:408)
  &gt;   at
  &gt; java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
  &gt;   at
  &gt; java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
  &gt;   at java.lang.Thread.run(Thread.java:745)
  &gt; 
  &gt; Driver stacktrace:    at
  &gt; org.apache.spark.scheduler.DAGScheduler.org$apache$spark$scheduler$DAGScheduler$$failJobAndIndependentStages(DAGScheduler.scala:1887)
  &gt;   at
  &gt; org.apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1.apply(DAGScheduler.scala:1875)
  &gt;   at
  &gt; org.apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1.apply(DAGScheduler.scala:1874)
  &gt;   at
  &gt; scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
  &gt;   at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:48)
  &gt;   at
  &gt; org.apache.spark.scheduler.DAGScheduler.abortStage(DAGScheduler.scala:1874)
  &gt;   at
  &gt; org.apache.spark.scheduler.DAGScheduler$$anonfun$handleTaskSetFailed$1.apply(DAGScheduler.scala:926)
  &gt;   at
  &gt; org.apache.spark.scheduler.DAGScheduler$$anonfun$handleTaskSetFailed$1.apply(DAGScheduler.scala:926)
  &gt;   at scala.Option.foreach(Option.scala:257)   at
  &gt; org.apache.spark.scheduler.DAGScheduler.handleTaskSetFailed(DAGScheduler.scala:926)
  &gt;   at
  &gt; org.apache.spark.scheduler.DAGSchedulerEventProcessLoop.doOnReceive(DAGScheduler.scala:2108)
  &gt;   at
  &gt; org.apache.spark.scheduler.DAGSchedulerEventProcessLoop.onReceive(DAGScheduler.scala:2057)
  &gt;   at
  &gt; org.apache.spark.scheduler.DAGSchedulerEventProcessLoop.onReceive(DAGScheduler.scala:2046)
  &gt;   at org.apache.spark.util.EventLoop$$anon$1.run(EventLoop.scala:49)
  &gt;   at
  &gt; org.apache.spark.scheduler.DAGScheduler.runJob(DAGScheduler.scala:737)
  &gt;   at org.apache.spark.SparkContext.runJob(SparkContext.scala:2061)    at
  &gt; org.apache.spark.SparkContext.runJob(SparkContext.scala:2082)     at
  &gt; org.apache.spark.SparkContext.runJob(SparkContext.scala:2101)     at
  &gt; org.apache.spark.sql.execution.SparkPlan.executeTake(SparkPlan.scala:365)
  &gt;   at
  &gt; org.apache.spark.sql.execution.CollectLimitExec.executeCollect(limit.scala:38)
  &gt;   at
  &gt; org.apache.spark.sql.Dataset.org$apache$spark$sql$Dataset$$collectFromPlan(Dataset.scala:3384)
  &gt;   at
  &gt; org.apache.spark.sql.Dataset$$anonfun$head$1.apply(Dataset.scala:2545)
  &gt;   at
  &gt; org.apache.spark.sql.Dataset$$anonfun$head$1.apply(Dataset.scala:2545)
  &gt;   at org.apache.spark.sql.Dataset$$anonfun$53.apply(Dataset.scala:3365)
  &gt;   at
  &gt; org.apache.spark.sql.execution.SQLExecution$$anonfun$withNewExecutionId$1.apply(SQLExecution.scala:78)
  &gt;   at
  &gt; org.apache.spark.sql.execution.SQLExecution$.withSQLConfPropagated(SQLExecution.scala:125)
  &gt;   at
  &gt; org.apache.spark.sql.execution.SQLExecution$.withNewExecutionId(SQLExecution.scala:73)
  &gt;   at org.apache.spark.sql.Dataset.withAction(Dataset.scala:3364)  at
  &gt; org.apache.spark.sql.Dataset.head(Dataset.scala:2545)     at
  &gt; org.apache.spark.sql.Dataset.take(Dataset.scala:2759)     at
  &gt; org.apache.spark.sql.Dataset.getRows(Dataset.scala:255)   at
  &gt; org.apache.spark.sql.Dataset.showString(Dataset.scala:292)    at
  &gt; sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)   at
  &gt; sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  &gt;   at
  &gt; sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  &gt;   at java.lang.reflect.Method.invoke(Method.java:483)     at
  &gt; py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)  at
  &gt; py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)    at
  &gt; py4j.Gateway.invoke(Gateway.java:282)     at
  &gt; py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
  &gt;   at py4j.commands.CallCommand.execute(CallCommand.java:79)   at
  &gt; py4j.GatewayConnection.run(GatewayConnection.java:238)    at
  &gt; java.lang.Thread.run(Thread.java:745) Caused by:
  &gt; org.apache.spark.api.python.PythonException: Traceback (most recent
  &gt; call last):   File
  &gt; "/Users/sabbar/anaconda3/lib/python3.6/site-packages/pyspark/python/lib/pyspark.zip/pyspark/worker.py",
  &gt; line 372, in main
  &gt;     process()   File "/Users/sabbar/anaconda3/lib/python3.6/site-packages/pyspark/python/lib/pyspark.zip/pyspark/worker.py",
  &gt; line 367, in process
  &gt;     serializer.dump_stream(func(split_index, iterator), outfile)   File
  &gt; "/Users/sabbar/anaconda3/lib/python3.6/site-packages/pyspark/python/lib/pyspark.zip/pyspark/serializers.py",
  &gt; line 390, in dump_stream
  &gt;     vs = list(itertools.islice(iterator, batch))   File "/Users/sabbar/anaconda3/lib/python3.6/site-packages/pyspark/python/lib/pyspark.zip/pyspark/util.py",
  &gt; line 100, in wrapper
  &gt;     return f(*args, **kwargs)   File "&lt;ipython-input-10-9aa45565a8c1&gt;", line 3, in csvParse
  &gt; ModuleNotFoundError: No module named 'StringIO'
  &gt; 
  &gt;   at
  &gt; org.apache.spark.api.python.BasePythonRunner$ReaderIterator.handlePythonException(PythonRunner.scala:452)
  &gt;   at
  &gt; org.apache.spark.api.python.PythonRunner$$anon$1.read(PythonRunner.scala:588)
  &gt;   at
  &gt; org.apache.spark.api.python.PythonRunner$$anon$1.read(PythonRunner.scala:571)
  &gt;   at
  &gt; org.apache.spark.api.python.BasePythonRunner$ReaderIterator.hasNext(PythonRunner.scala:406)
  &gt;   at
  &gt; org.apache.spark.InterruptibleIterator.hasNext(InterruptibleIterator.scala:37)
  &gt;   at scala.collection.Iterator$$anon$12.hasNext(Iterator.scala:440)   at
  &gt; scala.collection.Iterator$$anon$11.hasNext(Iterator.scala:409)    at
  &gt; scala.collection.Iterator$$anon$11.hasNext(Iterator.scala:409)    at
  &gt; scala.collection.Iterator$$anon$11.hasNext(Iterator.scala:409)    at
  &gt; org.apache.spark.sql.catalyst.expressions.GeneratedClass$GeneratedIteratorForCodegenStage1.processNext(Unknown
  &gt; Source)   at
  &gt; org.apache.spark.sql.execution.BufferedRowIterator.hasNext(BufferedRowIterator.java:43)
  &gt;   at
  &gt; org.apache.spark.sql.execution.WholeStageCodegenExec$$anonfun$11$$anon$1.hasNext(WholeStageCodegenExec.scala:619)
  &gt;   at
  &gt; org.apache.spark.sql.execution.SparkPlan$$anonfun$2.apply(SparkPlan.scala:255)
  &gt;   at
  &gt; org.apache.spark.sql.execution.SparkPlan$$anonfun$2.apply(SparkPlan.scala:247)
  &gt;   at
  &gt; org.apache.spark.rdd.RDD$$anonfun$mapPartitionsInternal$1$$anonfun$apply$24.apply(RDD.scala:836)
  &gt;   at
  &gt; org.apache.spark.rdd.RDD$$anonfun$mapPartitionsInternal$1$$anonfun$apply$24.apply(RDD.scala:836)
  &gt;   at
  &gt; org.apache.spark.rdd.MapPartitionsRDD.compute(MapPartitionsRDD.scala:52)
  &gt;   at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:324)
  &gt;   at org.apache.spark.rdd.RDD.iterator(RDD.scala:288)     at
  &gt; org.apache.spark.rdd.MapPartitionsRDD.compute(MapPartitionsRDD.scala:52)
  &gt;   at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:324)
  &gt;   at org.apache.spark.rdd.RDD.iterator(RDD.scala:288)     at
  &gt; org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:90)    at
  &gt; org.apache.spark.scheduler.Task.run(Task.scala:121)   at
  &gt; org.apache.spark.executor.Executor$TaskRunner$$anonfun$10.apply(Executor.scala:402)
  &gt;   at org.apache.spark.util.Utils$.tryWithSafeFinally(Utils.scala:1360)
  &gt;   at
  &gt; org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:408)
  &gt;   at
  &gt; java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
  &gt;   at
  &gt; java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
  &gt;   ... 1 more
  </code></pre>
  
  <p>here is the code : </p>
  
  <pre><code>from pyspark.ml import Pipeline
  from pyspark.ml.classification import LogisticRegression
  from pyspark.ml.feature import HashingTF, Tokenizer
  from pyspark.sql import Row
  from pyspark.sql.functions import UserDefinedFunction
  from pyspark.sql.types import *
  import pyspark 
  #from pyspark import SparkContext
  #sc = SparkContext("local", "Simple App")
  from pyspark.context import SparkContext
  from pyspark.sql.session import SparkSession
  from py4j.protocol import Py4JJavaError
  
  def csvParse(s):
      import csv
      from StringIO import StringIO
      sio = StringIO(s)
      value = csv.reader(sio).next()
      sio.close()
      return value
  
  inspections = sc.textFile('Chicago_Street_Names.csv').map(csvParse)
  
  inspections.take(1)
  </code></pre>
  
  <p><strong>Please help me this is project to make next week</strong></p>