Pyspark Dataframe writing to AVRO error


Hi Friends,

I am trying to write my dataframe to AVRO format but am getting an error.

I tried these 2 versions of packages:

pyspark --master yarn --conf spark.ui.port=44335 --packages com.databricks:spark-avro_2.10:2.0.1


pyspark --master yarn --conf spark.ui.port=44335 --packages com.databricks:spark-avro_2.11:4.0.0

The error I get is this:

… .option(“header”, “true”).save("/user/macksv17/practice/files/orders_avro")
Traceback (most recent call last):
File “”, line 2, in
File “/usr/hdp/current/spark-client/python/pyspark/sql/”, line 397, in save
File “/usr/hdp/current/spark-client/python/lib/”, line 813, in call
File “/usr/hdp/current/spark-client/python/pyspark/sql/”, line 45, in deco
return f(*a, **kw)
File “/usr/hdp/current/spark-client/python/lib/”, line 308, in get_return_value
py4j.protocol.Py4JJavaError: An error occurred while calling
: java.lang.ClassNotFoundException: Failed to find data source: avro. Please use Spark package
at org.apache.spark.sql.execution.datasources.ResolvedDataSource$.lookupDataSource(ResolvedDataSource.scala:72)
at org.apache.spark.sql.execution.datasources.ResolvedDataSource$.apply(ResolvedDataSource.scala:219)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at py4j.reflection.MethodInvoker.invoke(
at py4j.reflection.ReflectionEngine.invoke(
at py4j.Gateway.invoke(
at py4j.commands.AbstractCommand.invokeMethod(
at py4j.commands.CallCommand.execute(
Caused by: java.lang.ClassNotFoundException: avro.DefaultSource

Please help.



Learn Spark 1.6.x or Spark 2.x on our state of the art big data labs

  • Click here for access to state of the art 13 node Hadoop and Spark Cluster


After launching pyspark with below command

pyspark --packages com.databricks:spark-avro_2.10:2.0.1

you can save avro file format below way,

dataframe.write.format("com.databricks.spark.avro").save("output path dir")
or"output path dir", "com.databricks.spark.avro”)


Thanks Sunil. It works now.