Install Python

Python is a high-level and general-purpose programming language and is a top choice for programmers (Google search). Part of the reason that it is a popular choice for scientists and engineers is the language versatility, online community of users, and powerful analysis packages such as Numpy and Scipy. This course uses Python 2.7 or Python 3.7+. Python is free and open-source and is easy to install with Anaconda (IPython, Jupyter, Spyder), PyCharm, or the distributions. Below is a tutorial on getting started with Python with a complete installation guide.

Python is a high-level and general-purpose programming language with data science and machine learning packages. Use the video below to install on Windows, MacOS, or Linux.

Install Python on Windows

Install Python on MacOS

Install Python on Linux

Install Packages

The power of Python is in the packages that are available either through package managers. Sometimes a script uses a package that is not yet installed. Once Python is installed, a package manager such as pip or conda can be used to install, remove, or update packages.

Below is an example on how to install the Gekko Optimization Suite from the command line (start cmd).

 pip install gekko

The gekko package name can be replaced with any available package name such as NumPy.

 pip install numpy

Install Packages with pip (Jupyter Notebook)

Anaconda has many of the packages included with the installation. Two ways to install packages are with conda or pip. Use the exclamation mark in Jupyter notebook to run a system level command as if it were run in the Anaconda prompt.

 !pip install gekko

Install Packages with pip (Python Script)

Packages can also be managed from a Python script by attempting to load the package with try. If the import fails, the except section imports pip and installs the package.

Load and Optionally Install Packages

    from pip import main as pipmain
    from pip._internal import main as pipmain

The gekko package name can be replaced with any available package. The pip package manager connects to an online repository to retrieve the latest version of the package and install it. Sometimes a package is needed on a computer that isn't connected to the internet or the package isn't available through pip. Below is information on installing a package wheel (whl) file.

Install Package Wheels (whl) Offline

The pip package manager can also be used to install local (previously downloaded) wheel (.whl) files but dependencies may not be automatically installed if not connected to the internet. Below is an example wheel file installation for NumPy version 1.13.1 and SciPy version 0.19.1 for Python 3.6 with 64-bit Python.

 pip install numpy-1.13.1+mkl-cp36-cp36m-win_amd64.whl
 pip install scipy-0.19.1-cp36-cp36m-win_amd64.whl

Use Christoph Gohlke's whl files for Windows installations. Many of the packages depend on the Visual C++ 2015 Redistributable (x64 and x86 for CPython 3.5 and 3.6) that is available from Microsoft. After installing the Visual C++ redistributable, download and install NumPy and SciPy packages (in that order) for Python 3.6 on Windows. The downloaded wheel file names should not be changed because the wheel file name verifies compatibility with the current Python version.

Assignment Completion

To show that you have Python installed, turn in a screenshot with information on the package that you installed. Make sure you have the standard packages such as Matplotlib, NumPy, and SciPy installed. To check which modules are installed use pip from the command line:

 pip list

This should print out a list of all the Python modules such as the following:

 cycler (0.10.0)
 matplotlib (2.0.2)
 numpy (1.13.1+mkl)
 pandas (0.19.2)
 pip (9.0.1)
 pyparsing (2.2.0)
 pyserial (3.3)
 python-dateutil (2.6.0)
 pytz (2017.2)
 setuptools (28.8.0)
 six (1.10.0)