Change in rainfall 2001-2016, global tropics

Map: Change in rainfall 2001-2016, global tropics

Upgrade to Anaconda3 and Python3

Contents - Introduction - Un-installing conda/Anaconda - Install anaconda3 - Organise and update Eclipse - Set Anaconda as the Python interpreter - Import existing projects - Converting from Python2 to Python3 - Resources

Introduction

This post describes how to migrate from Anaconda2 to Anaconda3. It was originally written in June 2018, but as Python2 (and thus Anaconda2) are being phased out the post is becoming redundant.

Regardless if you have Anaconda2 or Anaconda3 installed, you can run both python2 (2.7) and python3 (3.6) under both. You can create environments for both python versions and swap between them. You can also have both Anaconda2 and Anaconda3 installed at the same time. This article, however, describes how to un-install Anaconda2 and then install Anaconda3 and change Eclipse to use Python3 from Anaconda3.

Un-installing conda/Anaconda

Open a terminal window and type:

$ conda install anaconda-clean

When asked to Proceed ([y]/n)? answer y

When the installation is complete, enter

$ anaconda-clean –yes

Conda then creates a backup in your home directory, as reported at the prompt

/Users/YourUser/.anaconda_backup/YYYY-MM-DDTHHMMSS

You can remove the backup from the terminal, change directory (cd) to your home:

$ cd ~

Remove the backup by entering

$ rm -rf .anaconda_backup

If you installed Anaconda2 in your home directory (default) you can continue below, if not cd to the directory where you installed Anaconda2.

Remove Anaconda2 by entering

$ rm -rf anaconda2

Return to your home directory and remove (or comment out) the system PATH to Anaconda2 in .bash_profile.

$ sudo pico .bash_profile

To comment out just add “#” in front of the PATH to Anaconda2

# export PATH=”/Path/to/anaconda2/bin:$PATH”

Install anaconda3

Go to the anaconda main page, click the Download Anaconda link and get the Python 3 version (3.6 at time of writing).

When the installer has finished downloading, double click the Anaconda3…pkg installer and follow the instructions. For details see this article.

Open .bash_profile in pico (as above) to reset the PATH to your Anaconda3 installation. Save the edits and close and reopen all Terminal windows for the environment PATH to take effect. Check that conda was properly installed by typing at the prompt:

$ conda -V

To get information on the conda environment enter:

$ conda info –envs

The response should be similar to

base * /Users/YourUser/anaconda3

To update your Anaconda distribution execute the commands

$ conda update conda

and

$ conda update anaconda

For more details see previous article.

Organise and update Eclipse

If you are using Eclipse as your Integrated Development Environment (IDE) you need to update Eclipse to work against Python3 and Anaconda3. You can choose to start Eclipse with a new workspace (directory) or rename your existing (anconda2/python2) workspace (directory) and keep the same workspace. I choose to use the latter, and renamed my old workspace. When starting with Python3 later I will copy or import the python packages and modules manually piece by piece for re-assembling my projects in python3, while at the same time updating the code.

Set Anaconda as the Python interpreter

With Eclipse workbench up and running, select from the top menu:

Eclipse : preferences

In the Preferences window that opens, click the PyDev expansion icon (>) in the menu to the left. In the expanded sub-list click the expansion icon for Interpreters and click Python interpreter. In the window that opens, click the New button in the upper right corner. The dialog window Select Interpreters opens. In the Interpreter Executable text box you have to give the link to your Anaconda Python executable. Click the Browse button and navigate to where you installed Anaconda, and drill down to the Python executable:

‘path’/Anaconda3/bin/python

where ‘path’ is the path you choose for installing Anaconda. Click Finish/OK, and the dialog window Selection Needed appears. Accept the default selection (all listed items), and click Finish/OK again. All the selected Libraries and their associated Packages will be linked to your project, and show up in the lower frame of the Preferences window. When finished, click Apply and Close.

Import existing projects

If you did as me, you can import your old python2 projects directly to Python3. From the Eclipse main menu:

File : import

Expand the small icon for general and then select “Projects from Folder or Archive”, hit the next> key and in the “Import Source” text box enter the path, pr use the buttons for Directory or Archive to navigate to the the project you want to import.

Note that the imported directory will keep its original position. If you want it to be in your default workbench (directory) you must first copy it in place.

Converting from Python2 to Python3

Some functions need to be recoded when you change from Python2 to Python3, but you will discover that as you try to run your Python2 packages in Python3. All print statements must be put in parenthesis in Python3 and accessing dictionaries is slightly different.

Resources

Anaconda

Setup python with Anaconda by Jason Brownlee (Machine Learning Mastery).