Deconstructing xkcd.com/1987/

Deconstructing xkcd.com/1987/

On April 30, 2018, https://xkcd.com/1987/ got published. This wasn't the first time that Randall Munroe posted about Python (probably the most famous comic was his import antigravity one which became an actual module in the stdlib as an easter egg), but it was the first comic that people construed as negative towards Python.

The interesting thing is Randall never blamed Python for the situation he found his laptop in. If you read the alt text on this post you will notice he said:

The Python environmental protection agency wants to seal it in a cement chamber, with pictoral messages to future civilizations warning them about the danger of using sudo to install random Python packages.

So he admits that he did bad things. But people took the confusing nature of the comic as proof/justification to come out and either be upset at Python overall, be upset about deploying Python, or some other thing to be upset over. And when I suggested maybe we look at our install process, people replied with xkcd.com/927/ which wasn't helpful.

So this obviously touched a nerve. In this post I will break down the comic in an attempt to try an de-mystify what has happened to Randall's laptop. Some of it is Randall's own doing, some of it is Apple's doing, some of it is Homebrew (although you could argue Homebrew's point of existence is Apple's fault), and some of it is Python's. Hopefully by the end you will agree with me that no single person is at fault with this and that software is hard. 😁

The Comic

To make it easier to reference, here is the original comic (which is licensed under Creative Commons Attribution-NonCommercial 2.5 License):

xkcd_1987

The interpreters

OS-Python

Apple includes Python 2.7.10 out-of-the-box as the system Python for their own use. Unfortunately this interpreter is rather old and is linked against a very old version of OpenSSL. It's honestly best to avoid and to treat as a private tool/app for macOS' own needs (and which is generally good advice for any OS that happens to include Python by default).

anaconda

Some people might be wondering why the "Anaconda Python" node of the graph has no specified Python version. Well, that's because conda, the environment manager for Anaconda, lets you specify the Python you want to use. So if you download miniconda which just gives you conda, you can then construct environments as necessary without having to manage your Python installation manually. In other words, if you like conda you can stop here in terms of Python installations.

Homebrew-Python-3

Although most developers like macOS for its UNIX base, Apple never shipped a UNIX-level package manager, hence Homebrew came into being. And because Python is used very often as part of or to develop code running on UNIX systems, Randall had Homebrew install Python 3.6. Now I don't know if Randall installed this explicitly or if it got pulled in as part of a dependency in Homebrew, but it could affect whether he could have the Python install that came with miniconda be on his PATH.

homebrew-python-2

Everything that applied above to the Python 3 install by Homebrew applies to Python 2 from Homebrew.

Python-2.6

For the macOS install from python.org I really can't comment on without knowing why Randall had such an old version of Python installed. Maybe he was running some really old code? Perhaps his Mac is so old this was a reasonable version of Python to install early on? I also can't comment as to why he installed to begin with or why he never uninstalled it.

The tools

pip

Having pip installed is not a shocker. The real question is what interpreter pip is attached to? That's dependent on which Python interpreter was installed last in the earliest directory to have a Python interpreter in it. This is why you should always use python -m pip when executing pip to guarantee you are using pip with the interpreter you intend to install for.

another-pip

This ties into the comment I made above about not knowing which interpreter the pip command is attached to. The fact that there's more than one most likely stems to Python interpreters being installed into multiple bin directories with their accompanying pip command.

easy_install

easy_install is included in macOS's creaky old version of Python. Homebrew will also install it for Python 2.7. But that's not coming from the python.org installer and honestly shouldn't be used in today's pip world.

The paths

paths

  • /usr/local/Cellar is from Homebrew
  • /usr/local/opt is probably old Homebrew (or at least I remember Homebrew installing there back in the day)
  • **/Frameworks/ is macOS' Python install
  • ~/python/ is probably from Randall himself
  • ~/newenv/ is also from Randall himself
  • /usr/local/lib/python3.6/ is Homebrew
  • /usr/local/lib/python2.7/ is also Homebrew

folders-owned-by-root

This either represents the system install of Python or Randall's sudo-install of Python that he references in the alt text of the comic.

question-marks

Not even sure what this is supposed to even mean. 😄

path

Whatever PATH is set to is between Randall and his shell. 😉 Obviously it should be set to notice Python installed, so most likely contains /usr/bin and /usr/local/bin to get the system install and all the other installs of Python that he has.

pythonpath

Whatever PYTHONPATH is set to will be system-specific to Randall and not because of some installation of Python.

Conclusions

To me, the reason for this xkcd comic is for Randall to be self-deprecating and point out how he let the Python situation on his computer get out of hand. Unfortunately people don't always pick up on this and instead decide to point at this picture and say, "see, Python is messed up!" But if you take the time to really look at the comic you will notice that pretty much none if it is directly Python's own fault (not knowing what pip is pointing at is pretty much the only thing you could point at and say is still the Python community's fault).

So the next time someone decides to link to this comic as proof that Python has a problem, you can say that it's actually Randall's problem. 😁