Re-Installing Python

With any luck, the title of this post should be (will be) “Re-installing Python the Right Way.” The reason for this post is that while trying to install the, albeit experimental, iPython module that allows you to save iPython/Jupyter notebooks in a markdown format and not JSON, I was running into difficulties that seemed to be a function of the way MacPorts installs Jupyter, which was not allowing me to run jupyter from the command line. I.e., the only way I could get a Jupyter notebook was by using the deprecated ipython notebook.

I read around a bit, and it seems the preferred way to handle this is to use something like MacPorts, or Homebrew, for the base installation of Python and Pip and then to do everything from within pip.

Side note: since I plan on installing most of the packages into only my user space, and I am lazy and don’t want to type pip install --user every time, I made an alias and saved it in my `.bash_profile:

alias pinstall='pip install --user'

I used vi but use whatever editor lets you access that hidden file and do what needs to get done. Once I was done, I executed the file so its settings were current:

. ~/.bash_profile

(Note the space between the dot and the tilde.)

Having done this, I set about re-loading all the usual modules on which I depend numpy, scipy, etc. (I have a fuller list.) I was surprised by how quickly this process went, and I routinely checked to see how things were going by opening either a Python or iPython shell and importing a recently installed library.

At the end of the process, however, I still could not get jupyter at the command line. I tried a number of suggestions, but the only one that worked was to add the location of the jupyter executable to my PATH:


This strikes me as a real kludge, but it does work. After doing that, I could get jupyter notebook to work, and once I added the following to the Jupyter notebook config file I could open Markdown files as notebooks:

c.NotebookApp.contents_manager_class = 'ipymd.IPymdContentsManager'

So, the current state of [ipymd][] appears to be that line numbers do work, but you can’t convert or save an extant notebook as an md-formatted notebook. You have to create a markdown document first, then open it in Jupyter. But once you’ve done that, you have the full functionality of Jupyter.

This is going to require a bit of legwork for the current project on which I am working, but I think it’s going to make my collaborator, who is not a convert (yet!) to Jupyter, a whole lot happier.

Epistemological Pluralism

Recently, someone in The Humanist referenced the notion of epistemological pluralism: “Epistemological pluralism is a term used in philosophy, economics, and virtually any field of study to refer to different ways of knowing things, different epistemological methodologies for attaining a full description of a particular field.” (Wikipedia)

As I repeatedly tell people who want to dismiss quantitative or mathematical approaches to humanistic subjects/objects of study: it’s not that I am leaving traditional methods/approaches behind, it’s that I am acquiring additional methods/approaches. Biologists can both love a particular fern as well as study all ferns, all plants and understand a fern as representative of that larger class of objects/phenomena. I want the same thing for the things I study.

pandas Filters

Some things that pandas makes easy:

Action pandas code
View a Column df['name] or
View 2 Columns df[['name', 'name2']]
View First 2 Rows df[:2]
View All Rows Where Value > 50 df[df['value'] > 50]
View a Row df.ex['RowID']
View a Column df.ix[:, 'value']
View a “Cell” based on row and column df.ix['rowid', 'column']

e.g., males = df[(df[Gender] == 'male') & (df[Year] == 2014)]

LaTeX Notes

The last time I used LaTeX was to collaborate with Jonathan Goodwin on our examination of the disciplinary history of folklore studies using topic modeling. Having spent five weeks with computer scientists and mathematician’s at the NSF’s Culture Analytics program at UCLA’s Institute for Pure and Applied Mathematics, that LaTeX is simply the assumed way that one communicates research results. To be clear, I have always admired LaTeX both for its power and for its open source nature, it’s just that my previous adventures with it were rather stumbling affairs. This time around, I simply installed LaTeX — as texlive-latex — via MacPorts, and I’ve chosen to use Texpad as my editor. The experience could not have been more smooth. I am writing up some notes now in it, and while I confess my itch to weak some of the defaults is strong — I don’t particularly care for the default type face in LaTeX (I never have) — it works.

As I work through my own implementation, I find myself admiring things list Neil Lawrence’s LaTeX style guide for his group.

More on R Difficulties

I’m continuing to have difficulties within R: suddenly rJava doesn’t work and a version is not available for R 3.3.0. Time to re-activate 3.2.4:

sudo port activate R @3.2.4

3.3.0 is still around. Whenever the various R packages have caught up with “Somewhat Educational”, I can re-activate it and then uninstall 3.2.4, whose nickname I have forgotten:

sudo port uninstall R @3.2.4