How to set up Spark to use pandas managed by anaconda?

Viewed 824

We've updated the Spark version from 2.2 to 2.3, but admins didn't update the pandas. So our jobs fail with the following error:

ImportError: Pandas >= 0.19.2 must be installed; however, your version was 0.18.1

Our admin team suggested to created a VM downloading latest version from anaconda (using the command conda create -n myenv anaconda).

I did that and after activating the local environment using source activate myenv when I logged into pyspark2 then I found it was picking the new version of pandas.

But when I am submitting a job using spark2-submit command then it is not working. I did added the below configuration in the spark2-submit command

--conf spark.pyspark.virtualenv.enabled=true  
--conf spark.pyspark.virtualenv.type=conda 
--conf spark.pyspark.virtualenv.requirements=/home/<user>/.conda/requirements_conda.txt --conf spark.pyspark.virtualenv.bin.path=/home/<user>/.conda/envs/myenv/bin

Also I did zipped whole python 2.7 folder and passed that in the --py-files option along with other .py files --py-files /home/<user>/python.zip, but still getting the same version issue for pandas.

I tried to follow the instruction specified in the URL https://community.hortonworks.com/articles/104947/using-virtualenv-with-pyspark.html , but still no luck yet.

How to fix it and be able to spark2-submit with the proper pandas?

1 Answers

I think you may need to define environment variables such as SPARK_HOME and PYTHONPAH pointing to corresponding locations in your virtualenv.

export SPARK_HOME=path_to_spark_in_virtualenv
export PYTHONPATH=$SPARK_HOME/python
Related