Skip to content

Commit

Permalink
[SPARK-46910][PYTHON] Eliminate JDK Requirement in PySpark Installation
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?
Modifies the PySpark installation script to ask users to allow installation of the necessary JDK, if not already installed.

### Why are the changes needed?
Simplifying the PySpark installation process is a critical part of improving the new user onboarding experience. Many new PySpark users get blocked in the installation process, due to confusing errors from not having Java installed. This change simplifies the PySpark user onboarding process.

### Does this PR introduce _any_ user-facing change?
Yes, modifies the PySpark installation script.

### How was this patch tested?
Installing PySpark in virtual environments

### Was this patch authored or co-authored using generative AI tooling?
No

Closes apache#44940 from asl3/jdk-install.

Lead-authored-by: Amanda Liu <[email protected]>
Co-authored-by: Hyukjin Kwon <[email protected]>
Signed-off-by: Hyukjin Kwon <[email protected]>
  • Loading branch information
asl3 and HyukjinKwon committed Jan 30, 2024
1 parent 29355c0 commit 83fad32
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions bin/pyspark
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,33 @@ export PYSPARK_PYTHON
export PYSPARK_DRIVER_PYTHON
export PYSPARK_DRIVER_PYTHON_OPTS

# Attempt to find JAVA_HOME.
# If JAVA_HOME not set, install JDK 17 and set JAVA_HOME using a temp dir, and adding the
# temp dir to the PYTHONPATH.
if [ -n "${JAVA_HOME}" ]; then
RUNNER="${JAVA_HOME}/bin/java"
else
if [ "$(command -v java)" ]; then
RUNNER="java"
else
echo -n "JAVA_HOME is not set. Would you like to install JDK 17 and set JAVA_HOME? (Y/N) " >&2

read -r input

if [[ "${input,,}" == "y" ]]; then
TEMP_DIR=$(mktemp -d)
$PYSPARK_DRIVER_PYTHON -m pip install --target="$TEMP_DIR" install-jdk
export JAVA_HOME=$(PYTHONPATH="$TEMP_DIR" $PYSPARK_DRIVER_PYTHON -c 'import jdk; print(jdk.install("17"))')
RUNNER="${JAVA_HOME}/bin/java"
echo "JDK was installed to the path \"$JAVA_HOME\""
echo "You can avoid needing to re-install JDK by setting your JAVA_HOME environment variable to \"$JAVA_HOME\""
else
echo "JDK installation skipped. You can manually install JDK (17 or later) and set JAVA_HOME in your environment."
exit 1
fi
fi
fi

# Add the PySpark classes to the Python path:
export PYTHONPATH="${SPARK_HOME}/python/:$PYTHONPATH"
export PYTHONPATH="${SPARK_HOME}/python/lib/py4j-0.10.9.7-src.zip:$PYTHONPATH"
Expand Down

0 comments on commit 83fad32

Please sign in to comment.