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:

PATH=$PATH:/opt/local/bin:/opt/local/sbin:/opt/local/Library/Frameworks/Python.framework/Versions/3.4/bin

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.

Leave a Reply