Sometime it is necessary to pass environment variables to Spark executors. To pass environment variable to executors, use setExecutorEnv function of SparkConf class.

Code snippet

In the following code snippet, an environment variable name ENV_NAME is set up with value as 'ENV_Value'.

from pyspark import SparkConf
from pyspark.sql import SparkSession

appName = "Python Example - Pass Environment Variable to Executors"
master = 'yarn'

# Create Spark session
conf = SparkConf().setMaster(master).setAppName(
    appName).setExecutorEnv('ENV_NAME', 'ENV_Value')

spark = SparkSession.builder.config(conf=conf) \
    .getOrCreate()

copyright This page is subject to Site terms.

More from Kontext

local_offer spark local_offer how-to

visibility 2
thumb_up 0
access_time 2 hours ago

Spark is a robust framework with logging implemented in all modules. Sometimes it might get too verbose to show all the INFO logs. This article shows you how to hide those INFO logs in the console output. Spark logging level Log level can be setup using function pyspark.Spar...

open_in_new Spark

local_offer pyspark local_offer spark local_offer how-to

visibility 2
thumb_up 0
access_time 2 hours ago

This article shows how to change column types of Spark DataFrame using Python. For example, convert StringType to DoubleType, StringType to Integer, StringType to DateType. Construct a dataframe  Follow article  ...

open_in_new Spark

local_offer pyspark local_offer spark local_offer how-to

visibility 2
thumb_up 0
access_time 3 hours ago

This article shows how to add a constant or literal column to Spark data frame using Python.  Construct a dataframe  Follow article  Convert Python Dicti...

open_in_new Spark

local_offer pyspark local_offer spark local_offer how-to

visibility 2
thumb_up 0
access_time 3 hours ago

This article shows how to 'delete' column from Spark data frame using Python.  Construct a dataframe  Follow article  Convert Python Dictionary List to P...

open_in_new Spark

comment Comments (0)

comment Add comment

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

No comments yet.

Kontext Column

Created for everyone to publish data, programming and cloud related articles. Follow three steps to create your columns.


Learn more arrow_forward