Macos – Removing all but original system-default python on macOS

homebrewmacospippython

I am trying to clean up the various Python installations on my MacBook Pro (macOS 10.13.4) by removing everything except the original system python (2.7.2 for the current version of macOS). I have had installations from python.org, macports, and homebrew at one time or another, and I think I have been able to delete everything these installations touched, but my system python still yells at me when I try to install a module.

After removing the homebrew python and pip installations, and deleting old folders from the macports install, I updated my ~/.bash_profile to contain just my .bashrc config and iTerm2 utilities. I then installed PIP for the system python using easy_install. However, when I try to install a package, for instance voltron, I get the following errors, and the installation does not finish.

matplotlib 1.3.1 requires nose, which is not installed.
python-dateutil 2.6.1 has requirement six>=1.5, but you'll have six 1.4.1 which is incompatible.
prompt-toolkit 1.0.15 has requirement six>=1.9.0, but you'll have six 1.4.1 which is incompatible.
blessed 1.14.2 has requirement six>=1.9.0, but you'll have six 1.4.1 which is incompatible.
matplotlib 1.3.1 has requirement numpy>=1.5, but you'll have numpy 1.8.0rc1 which is incompatible.

which python returns /usr/bin/python and which pip returns /usr/local/bin/pip

I would like to get my computer back to the state it was in when it came out of the box, but I do not want to do a wipe-and-reinstall. I have tried using macOS Recovery Mode to reinstall macOS, but it didn't change the error, so it seems there are some lingering references to these packages somewhere. How can I restore the original state of Python?


$> pip -V
pip 10.0.0b2 from /Library/Python/2.7/site-packages/pip-10.0.0b2-py2.7.egg/pip (python 2.7)

Looks like it actually did end up installing Voltron, but it is still showing an error for the missing dependencies. Here is what happens when I try installing one of them (six, in this case)

$> pip install --user six
Requirement already satisfied: six in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (1.4.1)
python-dateutil 2.6.1 has requirement six>=1.5, but you'll have six 1.4.1 which is incompatible.
prompt-toolkit 1.0.15 has requirement six>=1.9.0, but you'll have six 1.4.1 which is incompatible.
blessed 1.14.2 has requirement six>=1.9.0, but you'll have six 1.4.1 which is incompatible.
matplotlib 1.3.1 has requirement numpy>=1.5, but you'll have numpy 1.8.0rc1 which is incompatible.

Update – value of sys.path

$> python -c "import os, sys; print(os.linesep.join(sys.path))"

/Library/Python/2.7/site-packages/pip-10.0.0b2-py2.7.egg
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
/Users/emroch/Library/Python/2.7/lib/python/site-packages
/Library/Python/2.7/site-packages
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC

Best Answer

I was having a similar issue when installing pacages with PIP and seems that the cause of the problem is this https://github.com/pypa/pip/issues/5196

I could solve the issue following what is proposed here https://stackoverflow.com/questions/27630114/matplotlib-issue-on-os-x-importerror-cannot-import-name-thread

sudo pip uninstall python-dateutil
sudo pip install python-dateutil==2.2

from @oriol-nieto answer

python was using an old version of six, which I removed by typing:

rm -rf /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six.*