• python programming setup miniconda 848px

Code Basics – Best Python Programming Setup

posted in: Tutorial | 0

Python Programming Setup Options?

Have you started Python programming but asked yourself the following questions –

Is it best to install the Python 2.7.x environment or Python 3.6.x environment?

What is PIP and how do you manage different Python packages or libraries that you’ll need when programming in Python?

 

python programming options miniconda 848px

 

If you have these questions and more, we’ll so did I and it resulted in me running into a few road blocks at some point when trying to make useful apps with Python programming.

The best option is to use Miniconda so you can maintain multiple Python versions on a single computer and easily manage packages for each Python environment.

 




The Simple Option (But I don’t recommend it !)

If you head over to the official Python website https://www.python.org and click on the “Download” button you will get an option to download the installer for your operating system, for either Windows, Mac or Linux.

 

 

If you are on a Windows 10 machine like me, you will download either a .exe or .msi installer file with options for a 32-bit or 64-bit installation from the Python Releases for Windows page.

The installer comes pre-bundled with IDLE, pip and the Python documentation for the version that you have downloaded.

IDLE is the basic Integrated DeveLopment Environment for Python (however, you can just use your favourite text editor… mine is Sublime Text and I’ll show you how to set that up below).

PIP is a package management system used to install and manage software packages written in Python. You can find over 137,000 python packages listed in PyPI which is the official Python Package Index (PyPI) !! (only surpassed by the number of packages in the NodeJS community)

 

 

Although this simple Python setup is okay if you want to just get up and running to start with some basic Python programming, if you are really planning to invest some time in Python with importing packages and modules, writing Python apps, or learning Python for data analysis and artificial intelligence… I highly recommend that you use the ‘Better’ Python setup option that I describe next.

Trust me…. I’ve gone down the ‘Simple’ Python setup option before and hit many road blocks when trying to either switch back and forth to Python 2.7.x from Python 3.6.x (and vica versa), install and try out new packages like Google’s TensorFlow, and attempt cross-platform mobile and desktop app development using the awesome open source Kivy framework.

 

The Better Option (Miniconda)

The cleanest and most flexible way to set your Python programming environment is to use Miniconda.

 

What the heck is this Miniconda?

Directly from the website it states –

A free minimal installer for conda. Miniconda is a small, bootstrap version of Anaconda that includes only conda, Python, the packages they depend on and a small number of other useful packages, including pip, zlib and a few others.

 

But… then… What the heck is this “conda”?

Again… directly from the website… conda is –

The package and environment manager program bundled with Anaconda that installs and updates conda packages and their dependencies. Conda also lets you easily switch between conda environments on your local computer.

 

Who makes this “conda” and “Miniconda”?

Both come from the Python and R distribution called Anaconda from the company Anaconda Inc (previously known as Continuum Analytics).

 

Why don’t I just install Anaconda then… instead of Miniconda?

You can. But… the Anaconda distribution is over 500MB in size and contains more than 1000+ packages (most of those you’ll probably never use if you are just starting out with Python programming)

 

Setting up Python with Miniconda on Windows

To get started with python programming, first head over to the Miniconda Installer page at Conda.io.

Choose either the 3.6 or 2.7 installer (it really doesn’t matter because you can create a specific Python 3.6 or Python 2.7 environment with Conda as we’ll see shortly).

 

 

For this demo, I downloaded the 64-bit version of the Python 3.6 Miniconda Installer.

Click on the installer and follow the instructions for the installation wizard.

The default install location on my computer was “C:\ProgramData\Miniconda3”.

If you do not have any other Python installations on your computer, you can select “Add Anaconda to the system PATH environment variable”. Although this gives a warning it will allow you to simply open up Windows command prompt to use Miniconda. Otherwise you will have to launch the alternative Anaconda command prompt.

Ensure that “Register Anaconda as the system Python 3.6” check box is selected.

 

Using Miniconda on Windows

Now that Miniconda is installed on the machine, let’s try it out to see how it works to manage our Python programming environments.

You will have the initial default Python 3.6 programming environment setup when you installed Miniconda.

Go to the Windows Start or Search and open up a Window command prompt by typing CMD. (Alternatively if you did not set the PATH variable during the installation you will need to open Anaconda Prompt)

Using conda info

In the command prompt type in conda info

You should get details on your Miniconda environment setup like that shown below –

 

 

Using conda env list

Verify that you currently only have 1 Python programming environment with the command conda env list

The default Python programming environment is called ‘base’ and the path to it’s location on your computer is shown –

 

 

Using conda list

Let’s check what the default packages/modules are that were installed in the ‘base‘ Python programming environment, type in conda list

You can see here the version of Python installed was 3.6.4 and other useful packages were installed in the ‘base‘ Python programming environment such as the ‘urllib3‘ package.

 

 

Using conda create

Let’s make a new Python programming environment (separate from our ‘base‘ environment) that will be based on the legacy Python 2.7.

Type in conda create --name py27 python=2.7

You will get a prompt to indicate that a number of default packages will be downloaded, type in ‘y‘ to proceed and create your new Python programming environment.

 

 

Verify that you currently now have 2 Python programming environments with the command conda env list

There should be one called ‘base‘ and another called ‘py27‘.

 

 

Using activate

To switch to your new Python 2.7 environment, you need to make it your current activate environment. Type in the command activate py27

You will now see that Windows command prompt indicates the new Python 2.7 environment is activate by showing ‘(py27)’ in front of the dialog.

You can also verify the active environment and checking the Python programming environment that has an asterix * next to the environment name as shown here –

 

 

Check the default packages installed in the new Python 2.7 environment again with the command conda list

 

 

Using conda install

Install a new package called Numpy in the new Python 2.7 environment with the command conda install numpy

You will get a prompt to indicate that a number of default packages with Numpy, type in ‘y‘ to proceed.

 

 

Verify Numpy is installed in the ‘py27’ Python 2.7 environment again by listing the Python packages in it using the command conda list

You will see Numpy is install (version 1.14.2 shown below)

 

 

Launch python Interpreter

Launch the Python interpreter in this currently active ‘py27’ environment by simply typing in python

You will see that Python 2.7.14 is active as shown, and you can enter in a few simply Python commands to try it out –

 

 

Type in exit() to step out of the Python interactive session.

Using deactivate

To get back to the ‘base’ environment (Python 3.6) you can type either deactivate or activate base

Again, launch the Python interpreter in this currently active ‘base’ environment by simply typing in python

You will see that Python 3.6.4 is active as shown, and you can enter in a few simply Python commands to try it out –

 

 

Again, type in exit() to step out of the Python interactive session.

 

In the next session we’ll configure the Sublime Text editor for our new Python programming environments created with Miniconda.

Stay tuned…

 

 

 

Leave a Reply