<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Issue with Python Package Management in Spark application in Get Started Discussions</title>
    <link>https://community.databricks.com/t5/get-started-discussions/issue-with-python-package-management-in-spark-application/m-p/67797#M7191</link>
    <description>&lt;P&gt;In a pyspark application, I am using set of python libraries. In order to handle python dependencies while running pyspark application, I am using the approach provided by spark :&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Create archive file of Python virtual environment using required set of libraries&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;Pass this archive file with --archive option in spark-submit command&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;Reference : &lt;A href="https://spark.apache.org/docs/3.3.2/api/python/user_guide/python_packaging.html" target="_blank" rel="noopener"&gt;https://spark.apache.org/docs/3.3.2/api/python/user_guide/python_packaging.html&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;As mention in above document, Need to set following environment variables before running spark-submit command :&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&lt;STRONG&gt;export PYSPARK_DRIVER_PYTHON=python # Do not set in cluster modes.&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;export PYSPARK_PYTHON=./environment/bin/python&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;spark-submit --archives pyspark_conda_env.tar.gz#environment app.py&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;But when I am running application on data bricks cluster, I am getting following error&lt;BR /&gt;&lt;STRONG&gt;Path not found : ./environment/bin/python&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I checked, this archive file is present in different directories in driver and executor nodes. There is no classpath directory as such and due to this I can not use relative path for PYSPARK_PYTHON.&lt;/P&gt;&lt;P&gt;Following are directories where archive file is present in different nodes&lt;BR /&gt;&lt;STRONG&gt;driver : /local_disk0/spark-xxxxxx-xxxx-xxxx/userFiles-xxxxx-xxxxx-xxxxx/&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;executor : /local_disk0/spark-xxxxx-xxxxx-xxxxx/executor-xxxxxx-xxxxxx-xxxxxxxx/spark-xxxxx-xxxx-xxxxx-xxxx/&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Please suggest, if this is correct way or is there any other way to handle python dependencies for spark application.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Version : Databricks Runtime Version 12.2 LTS (includes Apache Spark 3.3.2, Scala 2.12)&lt;/STRONG&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 01 May 2024 09:55:33 GMT</pubDate>
    <dc:creator>Abhay_1002</dc:creator>
    <dc:date>2024-05-01T09:55:33Z</dc:date>
    <item>
      <title>Issue with Python Package Management in Spark application</title>
      <link>https://community.databricks.com/t5/get-started-discussions/issue-with-python-package-management-in-spark-application/m-p/67797#M7191</link>
      <description>&lt;P&gt;In a pyspark application, I am using set of python libraries. In order to handle python dependencies while running pyspark application, I am using the approach provided by spark :&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Create archive file of Python virtual environment using required set of libraries&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;Pass this archive file with --archive option in spark-submit command&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;Reference : &lt;A href="https://spark.apache.org/docs/3.3.2/api/python/user_guide/python_packaging.html" target="_blank" rel="noopener"&gt;https://spark.apache.org/docs/3.3.2/api/python/user_guide/python_packaging.html&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;As mention in above document, Need to set following environment variables before running spark-submit command :&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&lt;STRONG&gt;export PYSPARK_DRIVER_PYTHON=python # Do not set in cluster modes.&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;export PYSPARK_PYTHON=./environment/bin/python&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;spark-submit --archives pyspark_conda_env.tar.gz#environment app.py&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;But when I am running application on data bricks cluster, I am getting following error&lt;BR /&gt;&lt;STRONG&gt;Path not found : ./environment/bin/python&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I checked, this archive file is present in different directories in driver and executor nodes. There is no classpath directory as such and due to this I can not use relative path for PYSPARK_PYTHON.&lt;/P&gt;&lt;P&gt;Following are directories where archive file is present in different nodes&lt;BR /&gt;&lt;STRONG&gt;driver : /local_disk0/spark-xxxxxx-xxxx-xxxx/userFiles-xxxxx-xxxxx-xxxxx/&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;executor : /local_disk0/spark-xxxxx-xxxxx-xxxxx/executor-xxxxxx-xxxxxx-xxxxxxxx/spark-xxxxx-xxxx-xxxxx-xxxx/&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Please suggest, if this is correct way or is there any other way to handle python dependencies for spark application.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Version : Databricks Runtime Version 12.2 LTS (includes Apache Spark 3.3.2, Scala 2.12)&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 01 May 2024 09:55:33 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/issue-with-python-package-management-in-spark-application/m-p/67797#M7191</guid>
      <dc:creator>Abhay_1002</dc:creator>
      <dc:date>2024-05-01T09:55:33Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Python Package Management in Spark application</title>
      <link>https://community.databricks.com/t5/get-started-discussions/issue-with-python-package-management-in-spark-application/m-p/67804#M7192</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have not tried it but based on the doc&amp;nbsp;you have to go by this approach.&amp;nbsp;&lt;CODE&gt;&lt;SPAN&gt;./environment/bin/python&lt;/SPAN&gt;&lt;/CODE&gt;must be replaced with the correct path.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;&lt;SPAN&gt;import&lt;/SPAN&gt;&lt;SPAN&gt; os
&lt;/SPAN&gt;&lt;SPAN&gt;from&lt;/SPAN&gt;&lt;SPAN&gt; pyspark.sql &lt;/SPAN&gt;&lt;SPAN&gt;import&lt;/SPAN&gt;&lt;SPAN&gt; SparkSession
&lt;/SPAN&gt;
&lt;SPAN&gt;os.environ[&lt;/SPAN&gt;&lt;SPAN&gt;'PYSPARK_PYTHON'&lt;/SPAN&gt;&lt;SPAN&gt;] = &lt;/SPAN&gt;&lt;SPAN&gt;"./environment/bin/python"&lt;/SPAN&gt;
spark = SparkSession.builder.config(
    &lt;SPAN&gt;"spark.archives"&lt;/SPAN&gt;&lt;SPAN&gt;,  # &lt;/SPAN&gt;&lt;SPAN&gt;'spark.yarn.dist.archives'&lt;/SPAN&gt; &lt;SPAN&gt;in&lt;/SPAN&gt;&lt;SPAN&gt; YARN.
&lt;/SPAN&gt;    &lt;SPAN&gt;"pyspark_conda_env.tar.gz#environment"&lt;/SPAN&gt;&lt;SPAN&gt;).getOrCreate()&lt;/SPAN&gt;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;In the post, one of the reply does explain&amp;nbsp;&lt;SPAN&gt;The env_dir variable is set to the directory where the conda environment is unpacked by Spark.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://community.databricks.com/t5/machine-learning/how-to-use-spark-submit-python-task-with-the-usage-of-archives/td-p/10476" target="_blank"&gt;https://community.databricks.com/t5/machine-learning/how-to-use-spark-submit-python-task-with-the-usage-of-archives/td-p/10476&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 01 May 2024 10:29:11 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/issue-with-python-package-management-in-spark-application/m-p/67804#M7192</guid>
      <dc:creator>NandiniN</dc:creator>
      <dc:date>2024-05-01T10:29:11Z</dc:date>
    </item>
  </channel>
</rss>

