Recent Posts

Thursday, February 15, 2018

Installation Instructions For The Python sfc_models Package

The following text is an excerpt from An Introduction to SFC Models Using Python (Section 2.2). Although I obviously want to sell copies of my book, I want users to be able to use the package first for free. For an experienced Python programmer, the installation is very easy, as sfc_models is a vanilla Python package. However, many of my readers will not be familiar with Python, and would need some guidance in order to set it up.

I added in a file that describes the installation (at a high level) in the package, which users will hopefully see if they look at the GitHub repository. At some point, I would like to build up a free PDF that describes how to install and run examples. (Helping with documentation is one of the most pressing needs for outside help.)


Python is an open source programming language, and so it can be downloaded at no cost. The user is free to do what they wish with the software, so long as they follow the terms of the licence agreement. (The sfc_models package is also distributed in this fashion.)

I will not offer instructions on how to install Python; the procedures depend upon the computer’s operating system. There is a great deal of troubleshooting information available on the internet.

The key decision is whether you wish to download the base Python installation or work with an integrated development environment (IDE). I used to do my Python programming with the IDLE GUI (Graphical User Interface) that is installed by default with Python, but I have switched to using the PyCharm™ development environment by JetBrains: (https://www.jetbrains.com/pycharm/). PyCharm is available in two main editions: a free community edition that is sufficient for most programming and a commercial edition that is aimed at professional software developers. In addition, JetBrains has an edition for learning how to program: the user goes through lessons in steps. (There are other programming platforms available for Python; I am not familiar with them.)
Once you have installed Python, there are three ways of using the language.
  1. You can start the Python interpreter, and then type commands that are then processed. This interactive mode is useful for testing, but it is not the preferred way to do complex tasks. This interactive mode is similar to how Matlab and R are used, but not compiled languages (like C++).
  2. You can have the Python interpreter start running a script, and then it processes the commands within the script (Python scripts are files with the extension “.py”).
  3. You can work with a graphical development environment (IDLE, PyCharm) and develop Python scripts. You then launch the scripts using a command within the GUI. This is the usual way of developing in Python.
The advantage of working with Python scripts (*.py files) is that you can repeat the same steps without having to type them in again.

Once Python is installed, there are two ways of installing the sfc_models package: either downloading the latest Python package or by using the git source control system.

The easiest method is to load the latest production version that has been uploaded to the Python Package Repository (at pypi.org). The package is found at: https://pypi.python.org/pypi/sfc_models/. This download can either be done automatically through PyCharm, or else using the pip installation script on the command line.

The use of PyCharm is the simplest solution; you just need to add the sfc_models package to the Python installation, as described in the PyCharm documentation.

The slightly more complex solution is to use the pip installation script. The script is found in the “scripts” subdirectory below the Python installation. From the command line, you just need to run:

pip install sfc_models

However, you may need to do some steps before running “pip install,” and those steps may vary across operating systems. Since these installation methods will change over time, the reader is referred to online documentation on the usage of pip.

Code examples are found in the sfc_models/examples/scripts directory. You could find this directory, and copy the files to a working directory. Alternatively, you can run an installation script that is available once sfc_models is installed. To do this, open a Python console, and run the following.

from sfc_models.objects import *
install_examples()

Invoking install_examples should bring up pop-up windows that ask you where you wish to install the example scripts.

Using source control is discussed in Section 2.6.

(c) Brian Romanchuk 2017-2018

No comments:

Post a Comment

Note: Posts may be moderated, and there may be a considerable delay before they appear.

Although I welcome people who disagree with me, please be civil.

Please note that my spam comment filter appears to dislike long "anonymous" posts. I get no warning about this, and only go through my "spambox" infrequently. The best bet it to keep comments short, and if you think the spam filter struck, let me know with a short comment.