Hello, friends!

As I have mentioned before, I am using pyenv to manage multiple Python installations, but since I installed some Hombrew formulae that depend on python@3.9 I decided to uninstall Python 3 installed via pyenv and use the one from Homebrew.

So here I will share a quick guide on how I accomplished that.

  1. If you’ve installed Python 3.9.5 via pyenv, uninstall it by running uninstall and then rehash

     $ pyenv uninstall 3.9.5
     $ pyenv rehash
  2. Create a symlink at ~/.pyenv/versions

     $ cd ~/.pyenv/versions
     $ ln -sfv /usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9 3.9.5
     $ ls -al
     total 0
     drwxr-xr-x  5 thecesrom  staff   160 Jun  8 11:08 .
     drwxr-xr-x  6 thecesrom  staff   192 Jun  8 10:58 ..
     drwxr-xr-x  7 thecesrom  staff   224 Jun  8 10:58 2.7.18
     lrwxr-xr-x  1 thecesrom  staff    75 Jun  8 11:08 3.9.5 -> /usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9

    I chose /usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9 instead of /usr/local/Cellar/python@3.9/3.9.5 because I wanted to include the same folders (bin, include, lib, share) as my other Python installation (2.7.18), which I installed via pyenv.

  3. Create symlinks for idle, pip, python and wheel at the following location:

     $ cd /usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/bin
     $ ln -sfv idle3.9 idle
     idle -> idle3.9
     $ ln -sfv /usr/local/Cellar/python@3.9/3.9.5/bin/pip3 pip 
     pip -> /usr/local/Cellar/python@3.9/3.9.5/bin/pip3
     $ ln -sfv /usr/local/Cellar/python@3.9/3.9.5/bin/pip3 pip3
     pip3 -> /usr/local/Cellar/python@3.9/3.9.5/bin/pip3
     $ ln -sfv python3 python
     python -> python3
     $ ln -sfv /usr/local/Cellar/python@3.9/3.9.5/bin/wheel3 wheel
     wheel -> /usr/local/Cellar/python@3.9/3.9.5/bin/wheel3
  4. Once that’s done, run pyenv rehash as recommended by pyenv whenever you install new versions

     $ pyenv rehash
  5. Now, you’re ready to verify all versions managed by pyenv, and select a global, local, or shell version

     $ pyenv versions
     * system (set by /Users/thecesrom/.pyenv/version)
  6. If you want to set 3.9.5 as global, just run by running

     $ pyenv global 3.9.5
  7. Verify your selection by running

     $ pyenv versions
     * 3.9.5 (set by /Users/thecesrom/.pyenv/version)
  8. And now when I run python --version I get the following output:

     $ python --version
     Python 3.9.5

And that’s it! You’ve done it!

Thanks for reading and happy coding!