NameError: name 'dbutils' is not defined in pyspark

后端 未结 3 968
梦如初夏
梦如初夏 2021-01-18 09:17

I am running a pyspark job in databricks cloud. I need to write some of the csv files to databricks filesystem (dbfs) as part of this job and also i need to use some of the

3条回答
  •  -上瘾入骨i
    2021-01-18 10:02

    Try to use this:

    def get_dbutils(spark):
            try:
                from pyspark.dbutils import DBUtils
                dbutils = DBUtils(spark)
            except ImportError:
                import IPython
                dbutils = IPython.get_ipython().user_ns["dbutils"]
            return dbutils
    
    dbutils = get_dbutils(spark)
    

提交回复
热议问题