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 the latest Python 3.9 version via pyenv, uninstall it by running uninstall and then rehash

     pyenv uninstall 3.9.X
     pyenv rehash
    
  2. Create a symlink at ~/.pyenv/versions

     $ cd ~/.pyenv/versions
     $ ln -sfv "$(brew --prefix python@3.9)" 3.9
     $ ls -al
     total 0
     drwxr-xr-x  4 cesarcoatl  staff  128 Aug 31 07:51 .
     drwxr-xr-x  6 cesarcoatl  staff  192 Jun  8 10:58 ..
     drwxr-xr-x  6 cesarcoatl  staff  192 Aug 31 07:48 2.7.18
     lrwxr-xr-x  1 cesarcoatl  staff   25 Aug 31 07:51 3.9 -> /usr/local/opt/python@3.9
    
  3. If you wish to also include the include directory, run the following

     $ cd "$(brew --prefix python@3.9)"
     $ ln -sfv Frameworks/Python.framework/Versions/3.9/include/python3.9 include
     include -> Frameworks/Python.framework/Versions/3.9/include/python3.9
     $ ls -al
     total 64
     drwxr-xr-x  14 cesarcoatl  staff    448 Aug 31 07:43 .
     drwxr-xr-x   3 cesarcoatl  staff     96 Jul  3 09:36 ..
     drwxr-xr-x   3 cesarcoatl  staff     96 Jun 28 01:57 .brew
     drwxr-xr-x   3 cesarcoatl  staff     96 Jun 28 01:57 Frameworks
     drwxr-xr-x   3 cesarcoatl  staff     96 Jun 28 01:57 IDLE 3.app
     -rw-r--r--   1 cesarcoatl  staff   3770 Jul  3 09:36 INSTALL_RECEIPT.json
     -rw-r--r--   1 cesarcoatl  staff  13925 Jun 28 01:57 LICENSE
     drwxr-xr-x   3 cesarcoatl  staff     96 Jun 28 01:57 Python Launcher 3.app
     -rw-r--r--   1 cesarcoatl  staff  10140 Jun 28 01:57 README.rst
     drwxr-xr-x  19 cesarcoatl  staff    608 Aug 31 07:50 bin
     lrwxr-xr-x   1 cesarcoatl  staff     58 Aug 31 07:43 include -> Frameworks/Python.framework/Versions/3.9/include/python3.9
     drwxr-xr-x   3 cesarcoatl  staff     96 Jun 28 01:57 lib
     drwxr-xr-x   4 cesarcoatl  staff    128 Jun 28 01:57 libexec
     drwxr-xr-x   3 cesarcoatl  staff     96 Jun 28 01:57 share
    
  4. Create symlinks for idle, pip, python and wheel at the following location:

     $ cd "$(brew --prefix python@3.9)/bin"
     $ ln -sfv idle3 idle
     idle -> idle3
     $ ln -sfv pip3 pip 
     pip -> pip3
     $ ln -sfv python3 python
     python -> python3
     $ ln -sfv wheel3 wheel
     wheel -> wheel3
    
  5. Once that’s done, run pyenv rehash as recommended by pyenv whenever you install new versions

     pyenv rehash
    
  6. 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/cesarcoatl/.pyenv/version)
       2.7.18
       3.9
    
  7. If you want to set 3.9 as global, just run by running

     pyenv global 3.9
    
  8. Verify your selection by running

     $ pyenv versions
       system
       2.7.18
     * 3.9 (set by /Users/cesarcoatl/.pyenv/version)
    
  9. And now when I run python --version I get the following output:

     $ python --version
     Python 3.9.6
    

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

Thanks for reading and happy coding!