Before I took these steps, I ran brew uninstall python in an attempt to clear out a different Python installation. I also had to clear out some stuff in my .bash_profile.
- Install Pyenv via Homebrew:
brew update && brew install pyenv - Add necessary stuff to ~/.bash_profile:
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bash_profile - Restart terminal.
- Maybe install dependencies? (Thouhg you may be good to go already.)
pyenv install --listand pick new-ish-but-stable versions of python2 and python3 to install. For example:pyenv install 3.7.0 2.7.15- You can set version 3 as the global, with 2 as fall-back:
pyenv global 3.7.0 2.7.15. You can also set yoursystem's Python as a secondary fallback by runningpyenv global 3.7.0 2.7.15 system. - Check that
pipis installed (I think it's included?). You should be able to upgradepip3withpip3 install --upgrade pipandpip2withpip2 install --upgrade pip
Let's see how we did: If successful, python2 gets you Python 2, python3 or python gets you Python 3. You should get similar results with pip2/pip3/pip. To install a package, you'd run pip install <package-name>.
If you use Neovim + Deoplete, you probably want to run pip3 install neovim to ensure Deoplete works smoothly (see Deoplete's requirements). I also ran pip2 install neovim because :CheckHealth told me to. For Deoplete to work, you may need to run :UpdateRemotePlugins in Neovim. Neovim's :CheckHealth is your friend here.
These two blog posts may offer better, newer solutions:
- https://read.acloud.guru/my-python-setup-77c57a2fc4b6
- https://jacobian.org/2019/nov/11/python-environment-2020/
Specifically, if you only need Python so that you can install packages via pip (as opposed to active development using Python), I'm hoping that pipx may be a better, more self-contained solution. Users may even be able to bypass installing a python executable themselves?
For example, on MacOS, I'm hoping I can just do this in order to install the "neovim" package?:
brew install pipx
pipx ensurepath
pipx install neovim