Setting up Python on OS X¶
Getting The Tools¶
OS-X comes with Python out of the box, but not the full setup you’ll need for development, and this class. It also doesn’t have the latest version(s), and no versino of Python 3.
So we recommend installing a new version.
Note:
If you use macports
or homebrew
to manage *nix software on your machine, feel free to use those for python
, git
, etc, as well. If not, then read on.
Python¶
While OS-X does provide python out of the box – it tends not to have the
latest version, and you really don’t want to mess with the system
installation. So I recommend installing an independent installation from
python.org
:
Download and install Python 3.4.3 64/32 bit installer from Python.org:
https://www.python.org/ftp/python/3.4.3/python-3.4.3-macosx10.6.pkg
(you can probably use 3.5.0, too, but it’s brand new, and there are a number of third party pacakges that are not yet available for it)
Simple as that.
Oddly, this does NOT install a python
command, but rather a python3
command. If you want to be able to simply type python
and get python3, then you can add a symlink to the install:
$ cd /Library/Frameworks/Python.framework/Versions/3.5/bin
$ ln -s python3.5 python
(Or an alias in your shell – any Unix geeks here?)
Terminal¶
The built-in “terminal” application works fine. Find it in:
/Applications/Utilities/Terminal
Drag it to the dock to easy access.
git¶
Get a git client – the gitHub GUI client may be nice – I honestly don’t know.
There are a couple options for a command line client.
This one:
http://sourceforge.net/projects/git-osx-installer/
Is a big download and install, but has everything you need out of the box.
NOTE: if you get a warnign about it beign unsigned, you’ll need to go to yoru system preferences:
“Security and Privacy”
Then check the box saying “Open Anyway”. Or maybe check the box saying you can install untrused pacakges – depends on the OS-X version
This one:
http://git-scm.com/download/mac
Works great, but you need the XCode command line tools to run it. If you already have that, or expect to need a compiler anyway, then this is a good option.
You can get XCode from the Apple App Store.
(If you try running “git” on the command line after installing, it should send you there).
Warning: XCode is a BIG download. Once installed, run it so it can initialize itself.
After either of these is installed, the git
command should work:
$ git --version
git version 1.8.5.2 (Apple Git-48)
pip¶
pip
is the Python package installer. It is updated faster than python itself, so once you have python, you want to get the latest version of pip working:
$ python -m ensurepip --upgrade
[first make sure that python
gives you the one you want. You may need to call python3
instead]
It should download and install the latest pip
.
You can now use pip to install other packages.
iPython¶
One we are going to use in class is iPython
:
$ python3 -m pip install ipython[all]
You should now be able to run iPython
:
Python 3.5.0 (v3.5.0:374f501f4567, Sep 12 2015, 11:00:19)
Type "copyright", "credits" or "license" for more information.
IPython 4.0.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.