worker has different version 2.7 than that in driver 3.5
I am running Datalab on data proc cluster and when I run dataframe.write.csv() I got this error. Can someone help me please.
Exception: Python in worker has different version 2.7 than that in driver 3.5, PySpark cannot run with different minor versions.Please check environment variables PYSPARK_PYTHON and PYSPARK_DRIVER_PYTHON are correctly set.
I got the same issue when doing certain transfromation like joining 2 dataframes or using udf function
Exception: Python in worker has different version 3.6 than that in driver 3.7, PySpark cannot run with different minor versions.Please check environment variables PYSPARK_PYTHON and PYSPARK_DRIVER_PYTHON are correctly set.
I have checked the versions of both driver and workers are python 3.6.5 when starting but it changes to 3.7.0 in driver instance after applying the initial-action jupyter.
I got the same exception:
Exception: Python in worker has different version 3.6 than that in driver 3.7, PySpark cannot run with different minor versions.Please check environment variables PYSPARK_PYTHON and PYSPARK_DRIVER_PYTHON are correctly set.
The used job still worked on 2018-07-12. The code has not been modified in the meantime.
Found a solution for my problem on stackoverflow, maybe it helps you out too: https://stackoverflow.com/questions/51427175/error-while-running-pyspark-dataproc-job-due-to-python-version
Thanks @TheJP , the solution works for me.
@Khiem-Tran and @TheJP your issue is the same as #300 , and is related to Conda upgrading python on the master node but not workers.
@EagleDangar 's issue is different. I think it's the same as #249 -- Python 3 does not work with the datalab init action.
I'll put further discussion in those two issues and close this one as a duplicate of those two.
UPDATE THE SPARK ENVIRONMENT TO USE PYTHON 3.5 (Linux):
Open a new terminal and type the following command: "export PYSPARK_PYTHON=python3.5" This will ensure that the worker nodes use Python 3.5 (same as the Driver in Juypter) and not the default Python 2.6
DEPENDING ON VERSIONS OF PYTHON YOU HAVE, YOU MAY HAVE TO DO SOME UPDATES VIA ANACONDA:
Make sure you have anaconda 4.1.0 or higher. Open a new terminal and check your conda version by typing into a new terminal: "conda --version"
checking conda version
if you are below anaconda 4.1.0, type conda update conda
- Next we check to see if we have the library nb_conda_kernels by typing
"conda list"
Checking if we have nb_conda_kernels
- If you don’t see nb_conda_kernels type
"conda install nb_conda_kernels"
Installing nb_conda_kernels
- If you are using Python 2 and want a separate Python 3 environment please type the following
"conda create -n py35 python=3.5 ipykernel"
py35 is the name of the environment. You could literally name it anything you want.
If you are using Python 3 and want a separate Python 2 environment, you could type the following.
"conda create -n py27 python=2.7 ipykernel"
py27 is the name of the environment. It uses python 2.7.
- Ensure the versions of python are installed successfully, and close the terminal. Open a new terminal and type "pyspark". You should see the new environments appearing:
Check that both your PYSPARK_PYTHON and the python PATH used in pyspark should match. I solved this by running "which python" on spark server after I got my python path
Then I found that PYTHON_PATH on my .bashrc file was different, so I updated it with the path obtained above. Then I ran "source ./~bashrc" and restarted pyspark
This solved this version error for me.