User Tools

Site Tools


tutorials:python

Python Wiki

This page is geared toward getting students who may be interested in basic data science (and related stuff) off to a running start with Python, but it will probably be useful for other folks too. This wiki is an evolving project (typos and bad grammar included free of charge), so check back for updates.

Getting Started

Regardless of Operating System, I recommend that you use a Unix-like environment for running your Python code. Why? 1) There are tons of powerful, super-useful command-line tools that are often present with little exception in Unix-like environments. 2) Students may be using Macs, PCs, or Linux boxes for their projects. Keeping everyone using a similar environment helps everyone “be on the same page” and have equal capabilities. 3) If you run into a problem, a standard development environment makes it easier for you to help each other debug problems.

Some of the packages that you'll need include:

  • Python 3 (installing both 2.7 and 3 is possible too)
  • PIL or Pillow (with PIL-compat)
  • NumPy
  • MatPlotLib
  • SciPy
  • others to be added as the class progresses

Windows

There are a couple of ways to get Python running on Windows. The methods that I have personally worked with are Anaconda + Spyder, Ubuntu on Windows 10, and Cygwin. All have their strengths and weaknesses.

Anaconda + Spyder

This option is best if you do not want to get into the nuts and bolts of doing a command-line installation of Python. This is by far the easiest means of installing the needed packages. First, download the Anaconda installer. Run the installer and click “next” all the way through. The installation process may take a very long time…be patient. Once it is finished, open “Spyder 3” from your programs menu, and you're ready to begin coding.

Windows Subsystem for Linux

This is the recommended option. First, follow the official instructions from Microsoft for Installing Windows Subsystem for Linux. I suggest selecting Ubuntu as your distribution of choice during the installation.

Once you've got that installed, you should already have Python by default. Now, you'll need to install an X server. XMing is a pretty good, free option.

Open your Ubuntu command prompt and run these commands:

sudo apt-get install libfreetype6-dev
sudo apt-get install libxft-dev
sudo apt-get install python-wxtools
sudo apt-get install gfortran
sudo apt-get install libopenblas-dev
sudo apt-get install liblapack-dev
sudo apt-get install python3.7-tk
sudo pip3 install numpy
sudo pip3 install matplotlib
sudo pip3 install scipy
sudo apt-get install wget
sudo apt-get install w3m

Once those have finished installing, run this command:

echo "export DISPLAY=:0" >> ~/.bashrc

Close all of your open console/terminal windows and reopen them.

Make sure XMing (or whatever X server you have) is running BEFORE running your code. This is almost always the problem if you get an error similar to the following:

_tkinter.TclError: couldn't connect to display ":0"

Cygwin - DEPRICATED

This is not the recommended option for Windows users and specifically addresses Python 2.7. You can download these instructions HERE.

Mac OS X

There are several ways to get python and the needed libraries installed on Mac OS. The preferred method is using Homebrew package manager. If you are already using MacPorts, however, that is also a viable option, but it is not covered here. Below are the instructions for getting started with Homebrew.

Install Homebrew (Open Terminal from Applications/Utilities then copy/paste and run the install command from their website) As of August 2019, this command is:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

When the above command completes, open a terminal window and run the following commands (note that “Pillow” begins with a capital “P”):

brew install python
pip3 install matplotlib
pip3 install Pillow
brew install emacs     (The following are optional but highly recommended)
brew install w3m
brew install wget

Linux

If you're using Linux, you probably know how to do this already. Otherwise, use your default package manager (differs from one flavor of Linux to the next) to install the packages listed at the top of this tutorial.

Hypothetically, the follow commands should install all that is needed for Ubuntu users, but this has not been tested:

sudo apt-get install libfreetype6-dev
sudo apt-get install libxft-dev
sudo apt-get install python-wxtools
sudo apt-get install gfortran
sudo apt-get install libopenblas-dev
sudo apt-get install liblapack-dev
sudo easy_install-2.7 install numpy
sudo easy_install-2.7 install matplotlib
sudo easy_install-2.7 install scipy
sudo apt-get install wget      (The following are optional but highly recommended)
sudo apt-get install w3m
sudo apt-get install emacs
tutorials/python.txt · Last modified: 2021/08/01 22:06 by jones