- Newest
- Most votes
- Most comments
This issue appears to be related to the Python virtual environment configuration in your EMR cluster when executing PySpark UDFs. The error indicates that Spark is trying to create a Python virtual environment but failing when running the command /usr/bin/virtualenv.
There are a few approaches you can try to resolve this:
- Modify Spark Configuration: Instead of completely disabling virtual environments (which would prevent you from installing packages), you can try configuring how Spark handles Python environments. Add these configurations when creating your EMR cluster or through the Spark configuration:
spark.pyspark.python=/usr/bin/python3
spark.pyspark.driver.python=/usr/bin/python3
-
Use Bootstrap Actions: You can create a bootstrap action that ensures the virtualenv package is properly installed and configured on all nodes in your cluster.
-
Alternative UDF Approach: Try using Spark's pandas UDFs or vectorized UDFs which may handle the Python environment differently.
-
Check Python Dependencies: Ensure that all required Python packages for virtualenv are installed on your cluster nodes.
-
Notebook-scoped Libraries: If you're using EMR Notebooks, you can try installing notebook-scoped libraries on your running EMR cluster, which might provide a workaround for your package installation needs.
The issue is likely related to how EMR is configured to handle Python environments when executing UDFs across the cluster. The error occurs because Spark is trying to create isolated Python environments on worker nodes to execute your UDF, but the virtualenv command is failing.
Sources
Amazon EMR Notebooks - Amazon Web Services
spark env issues post custom ami creation for EMR on EC2 cluster stuck in steps failure | AWS re:Post
Amazon EMR Studio | Managed IDE Environment | Amazon Web Services
answered a year ago
After setting
%%configure -f
{"conf":{"spark.pyspark.python": "/usr/bin/python3",
"spark.pyspark.driver.python": "/usr/bin/python3"
}
}
the UDF error disappears but throws the error RuntimeError: install_pypi_packages can only use called when spark.pyspark.virtualenv.enabled is set to true when I try to call install_pypi_package. However, after setting
%%configure -f
{"conf":{"spark.pyspark.python": "/usr/bin/python3",
"spark.pyspark.driver.python": "/usr/bin/python3",
"spark.pyspark.virtualenv.enabled": "true"
}
}
It throws the error
The code failed because of a fatal error:
Neither SparkSession nor HiveContext/SqlContext is available..
Some things to try:
a) Make sure Spark has enough available resources for Jupyter to create a Spark context.
b) Contact your Jupyter administrator to make sure the Spark magics library is configured correctly.
c) Restart the kernel.
When I try to run any code.
answered a year ago
Relevant content
asked 6 years ago
asked 4 years ago
asked 3 years ago
