A Byte of my 2.2-lb Brain

Just sharing stuff…

MacPorts and Python 2.7

First things first, download MacPorts here—make sure you download the correct version for your OSX (e.g. Yosemite, Mavericks, Mountain Lion, etc.). Then install. Once the port command is working, you can start installing Python and its packages on your machine.

You can choose different versions of Python, but here we use Python 2.7.

$ sudo port install python27

After successfully installing Python, make sure that the newly installed version of Python is the one that is run when executing the command python. To do this, run the following.

$ sudo port select --set python python27

You may also want to install pip and set that version as the default as well.

$ sudo port install py27-pip
$ sudo port select --set pip pip27

Packages

Here are some of the basic Python packages you may need. Note that they all have the py27- prefix. This just indicates the Python version.

$ sudo port install py27-matplotlib py27-numpy py27-scipy py27-ipython
$ sudo port select --set ipython ipython27

Other packages you may be interested in are:

  • Pandas – Powerful data structures for data analysis and statistics
  • Seaborn – Statistical data visualization library
  • Scikit Learn – Easy-to-use and general-purpose machine learning in Python
  • Networkx – For graph manipulation
  • Graph Tool – Efficient python graph module; why I’m using MacPorts instead of Anaconda or Canopy.

Searching for Packages

If you need other packages, e.g. Networkx, you can check if MacPorts has them by executing the following command.

$ port search networkx

You will then get the following output, which lists all the available packages for each Python version.

py-networkx @1.9.1 (python, science)
NetworkX in a Python package for graph manipulation.

py26-networkx @1.9.1_1 (python)
this port is only a stub and has been made obsolete by py27-networkx

py27-networkx @1.9.1 (python, science)
NetworkX in a Python package for graph manipulation.

py31-networkx @1.9.1_1 (python)
this port is only a stub and has been made obsolete by py34-networkx

py32-networkx @1.9.1_1 (python)
this port is only a stub and has been made obsolete by py34-networkx

py33-networkx @1.9.1_1 (python)
this port is only a stub and has been made obsolete by py34-networkx

py34-networkx @1.9.1 (python, science)
NetworkX in a Python package for graph manipulation.

Since I have Python 2.7, I will install py27-networkx.

$ sudo port install py27-networkx

Package NOT on MacPorts

If the package that you need is not on MacPorts, use the following command to install.

$ python setup.py install --user

Note that sudo has been dropped in this case.

Broken Pipes

Fixing broken pipes can be a pain. To avoid such, whenever your installation gets interrupted (some port installations can take hours because of certain dependencies–you can get disconnected in the middle of the installation), you have to clean the port you are trying to install before re-installing it. To do this, just execute the script below.

$ sudo port clean --all -f py27-InterruptedPort
$ sudo port install py27-InterruptedPort

References

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Information

This entry was posted on April 14, 2015 by in Geek and tagged , , , .
%d bloggers like this: