How To Install Python the Easy Way

Python for Matlab Users, Part 2: Installing Python

Rasmus Gundorff Sæderup
The Startup
5 min readAug 31, 2020

--

This is part 2 of a series on introducing Matlab users to Python. Part 1 can be found here, where we looked into why one might switch from Python to Matlab.

Now that we have a rough idea of why we are embarking on this quest to tame the mighty Python, it’s finally time to start.

Lets begin our Python adventure! Photo by Danielle MacInnes on Unsplash

Step 1: Installing Python

The easiest way to install Python, is to download the Anaconda Distribution from the following link: https://www.anaconda.com/distribution/#download-section

There are a number of reasons why I recommend installing Anaconda instead of e.g. using the built-in Python distribution found on UNIX systems (Linux, osx):

  • It’s super easy to install and you don’t have to mess around with choosing the right Python version and having packages supporting that version
  • It provides a confined Python environment, i.e. whatever you do here doesn’t mess with your system’s Python which might be used for other things (trust me, from experience this is an important point!)
  • It comes with all the essential packages such as NumPy, TensorFlow, pandas, matplotlib etc. (more on this later)
  • It has its own package manager, Conda, which you can use for installing new packages (this can also be done in Python using pip, but Conda also handles packages outside Python)

A drawback of installing Anaconda is however the number of packages installed: Around 150 packages are bundled with Anaconda [1] which means it takes up ~3 GB of space. If you don’t have the disk space for this, you can instead install Miniconda [2] which just contains Python and the Conda installer. You can then install the packages you need manually.

Installing Anaconda

Installing Anaconda is super easy: You just download the installer from https://www.anaconda.com/distribution/#download-section and run it.

Note: If you’re like me and have special characters in your name, be aware that if you have any non-ASCII characters your windows user-name, Anaconda will not install correctly!

To fix this, simply change the install path to something with ASCII-only characters, or by choosing “install for all users” in which case the default install path with be in C:\ProgramData, i.e. something with ASCII-only characters.

Photo by Danial RiCaRoS on Unsplash

After installation, it’s now time to check if Conda works. There is one optional step to do first though, which I’d recommend you to do:

Add Anaconda to your PATH variable (Optional):

Click Windows+R to open the Run-dialog, and type sysdm.cpl to go to the environment variables dialog. Here, you go to Advanced->Environment Variables and edit the Path variable, by appending the path to where Anaconda installed the conda.exe file.

In my case it was located in C:\ProgramData\Anaconda3\Scripts .

C:\Users\dhe\AppData\Local\Continuum\anaconda3\Scripts

By doing this, you can run Conda from your normal terminal on your PC. You might have to restart you PC after this.

Step 2: Check if Conda is installed correctly:

There are three ways to run Conda: Either using the Anaconda Navigator, the Anaconda Prompt or the Windows Command Prompt. Both are described here:

Using Anaconda Navigator:

The Anaconda Navigator is the GUI which comes with Anaconda, from which you can install and launch various IDEs, see the image below. It can be launched by searching for Anaconda Navigator in the Windows Start menu.

The Anaconda Navigator start page.

From the Anaconda Navigator, you can launch the Windows Command Prompt (see below), so that you can check the Conda version.

Using Anaconda Prompt:

To check if you have Anaconda up and running, go to the Start Menu in Windows and search for Anaconda Prompt. It should open a terminal window.

In this window, type the following to verify Conda is running:

Using Windows Command Prompt (cmd):

Alternatively, if you added Anaconda to your PATH, you can also open up a regular command prompt window (Windows+R, type cmd).

Conda operates in so-called environments (to be explained later), which are confined areas where python can run in a certain configuration without influencing other environments with other configurations.

When running Conda in the terminal, the default (base) environment must be started manually. This is done by typing the following two commands:

From now on, the Conda base environment will be running by default when opening a new terminal. To disable this, simply type

However, you must then type

whenever you want to launch Conda from a new terminal.

You can now verify the Conda version just the same way as with the Anaconda Prompt:

Update Conda:

It’s always a good idea to keep Anaconda updated. You do this by typing the following in the Anaconda Prompt:

Note: Depending on how you installed Anaconda, it might be necessary to run the Anaconda Prompt as Administrator, in order to have the privileges to update Conda.

Step 3: Running Python

With Conda updated and running, we can now (finally!) start Python. As we would like to use the Python supplied with Anaconda, we cannot just write Python in our terminal to run it, as this might start the global Python installed on the OS. Instead, we must start it from Conda. We do this by starting conda using either the Anaconda Prompt or cmd (remember to activate the base environment if using the cmd). Then you can simply type:

and press Enter to launch Python! You should now see >>> in your terminal, which means you are in Python.

Having launched Python, you can now write your first two lines of Python code: The good old “hello-world”-example.

In the following, whatever is written in the same line as >>> is what you type, and anything without >>> what Python prints out.

So here we asked Python to print Hello World! and to calculate 2+3. Your terminal should now look something like this:

The terminal after launching Python, printing “Hello World!” and calculating 2+3.

Congrats! You have now written your first lines of Python code!

In the next part of this series, we will take a look at choosing and installing an IDE so that you can actually start writing some code.

--

--