Upgrading from Python 2.7 to Python 3.7 requires you to install Python 3.7 and then re-point all the libraries installed on Python 2.7 to Python 3.7. The process can be broken down into two main steps:
1. Install Python 3.7 and Set Default Python Version
2. Repoint Libraries from Python 2.7 to Python 3.7
Step 1: Install Python 3.7 and Set Default Python Version
1. Download the Python 3.7 installer from the official Python website (https://www.python.org/downloads/).
2. Run the installer and follow the instructions to install Python 3.7 on your system.
3. Once installed, check the location of the Python 3.7 executable file by running the following command in your terminal:
which python3.7
This will output the location of the Python 3.7 executable file. Make a note of this location as you will need it later.
4. To set Python 3.7 as the default Python version, you can create a symlink named “python” that points to the Python 3.7 executable file. Run the following command in your terminal:
sudo ln -s /usr/bin/python3.7 /usr/bin/python
This will create a symlink named “python” in the /usr/bin directory that points to the Python 3.7 executable file.
5. Verify that Python 3.7 is the default Python version by running the following command in your terminal:
python --version
This should output the version of Python 3.7 that you installed.
Step 2: Repoint Libraries from Python 2.7 to Python 3.7
1. Before repointing the libraries, it’s a good idea to create a backup of the existing libraries installed on Python 2.7. You can do this by running the following command in your terminal:
pip freeze > requirements.txt
This will create a file named “requirements.txt” that contains a list of all the libraries installed on Python 2.7.
2. To repoint the libraries to Python 3.7, you will need to reinstall them using the Python 3.7 version of pip. Run the following command in your terminal:
sudo apt-get install python3-pip
This will install the libraries listed in the “requirements.txt” file using the Python 3.7 version of pip.
Once the libraries have been installed, you can verify that they are installed correctly by running the following command in your terminal:
pip3 list
This should output a list of all the libraries installed on Python 3.7.
5. You can also check the location of the installed libraries by running the following command in your terminal:
pip3 show <library-name>
Replace <library-name> with the name of the library you want to check. This will output the location of the installed library.
Repeat steps 4 and 5 for all the libraries listed in the “requirements.txt” file to ensure that they have been correctly repointed to Python 3.7.
Refer more on python here : Python
Refer PySpark blogs here : PySpark Blogs