Uncluttering Python on my Mac

I just started out using Python a while ago and while my Python path isn’t XKCD material it is not neat. In fact I think it was the cause of a problem I had earlier in the week with an app I was trying to package.

So I want to clear house and start fresh(ish) and was looking for any tips or warnings anyone has. This is a fairly complex task and I want to get some feedback before I go further and really mess things up :slight_smile:

Currently I have the following installed

  • Mac Python
  • Homebrew
  • Anaconda
  • poetry
  • pip

The Mac install obviously has to stay as does the Homebrew install.

Can I remove them from the $PYTHONPATH without messing things up?

Anaconda is going as I have replacements for Spyder and Jupyter Notebook.

Ideally I would like a single directory that everything got installed in like ~/.python. Is that possible and/or advisable?

Also looking at pyenv or pipenv to help manage everything. Does anyone have any recommendations?


The Mac does present some unique challenged :slight_smile:

A couple thoughts:

  1. You really want one python system that you use for your own stuff, i.e. that would go on PATH.

  2. Apple provides a system Python at:


(actually, it look like they have a python2 and python3 now, at least on my system)

You don’t want to mess with that one, which means you don’t want to use it for your custom use, as you might (will) need to install additional packages, etc.

So it can happily be shadowned on your PATH – any system utilities that need it would be providing an explicit path to it.

  1. hombrew also provides Python – I haven’t used it for a while, so I can’t remember the detatils, but I imagine it is used by other stuff that homebrew installs, so it’s a bit like the system python. If you want to stay homebew focused, then it’s OK to use that Pytohn as your “user” python. Looking quickly at the homebrew docs:

indicates that, as a rule, anything that can be pip installed should be, rather than be a homebrew package. In fact, it says that a python-based appliation should “vender” any python dependencies.

SO using homebrew python as your Python should work fine – jsut make sure it’s on your PATH first.

  1. Python.org distributes a Python installer – it’s separate from the system one (as it should be) – it’s “killer feature” is that it includes support for running GUI-based apps (Framework Python) – so if you want to run Python GUIs on your Mac, this is a great choice. (I don’t think homebrew supoert that, but maybe?)

  2. The only other “easy” choice is conda Python. This can be installed either with the Anaconda system, or more simply with miniconda. Conda provides multipel versions of Python, and an environment system for managing it all – it is an fine choice, but only the obvious one if you use anything that is only (or most easily) available through conda – that used to be the “scipy Stack” but now most of the core scipy package can be pip installed, so it’s less killer, but it’s still the case (last I checked for the OSGEO stack (GDAL et al) and other “data science” stuff. Make sure you caheck out conda-forge – it GREATLY increases the number of pacakges available.

you mention poetry and pip – those are not Python installations, but tools that use an existing Python installation – they can be used with any of the above, though it’s better to use pip as little as possible with conda. (not sure how poetry interacts with conda)

Ideally I would like a single directory that everything got installed in like ~/.python. Is that possible and/or advisable?

no – not possible – each of the above will do it’s own thing. On the plus side, conda can (and it’s the default) puts everything inside your user dir – e.g. ~/miniconda

Once you choose which of the above you want to use, then all the others can be removed from your PATH

Also looking at pyenv or pipenv to help manage everything.

I’d say first steo is to decide if conda is right for you (It’s my personal go-to, and it’s NOT just for "data science:)

If you use conda, then use conda environments.

If you choose to use either homebrew Python or the Python.org Mac installers, then yes you will want o use either pyenv or pipenv (or virtualenv? I"ve lost track) – look elsewhere for advise on the that, it’s not Mac specific.

Final note about conda: if you go the conda route, I find it VERY helpful to set up a default environment that’s NOT the conda root environment. I have a “py3” environment that I activate in my startup script:

conda activate py3

in my .zshrc file.

That way I can make a mess of it, and start again clean, without break ing my entire conda install. It could be handy to have conda_requirements.txt file with the stuff you usually want handy, so you can make a new “default” environment easily.

There’s probably a similar way to do the same thing with the various pip-based environment management tools.

For how to get your Python, I’d say the safest option is using the official Mac installer from python.org:

Alternatives that work well:

  • I like pyenv quite a bit. If you want to access to older or different versions of Python, I’d use pyenv.
  • conda. Dr. Barker covers this option above.

Things I do not recommend:

That covers Python itself. Once you have a Python, you’ll need to use other tools to download and install packages and manage their locations. This is where pip / poetry / virtual environments come in.

There are a number of good tutorials for this on the internet. The one thing I’ll say is run python -m pip instead of just pip. This will help reduce confusion about which Python executable’s environment pip will install to.

Best of luck!

Thanks for the comments everyone