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.
-
If you’ve installed the latest Python
3.9version viapyenv, uninstall it by runninguninstalland thenrehashpyenv uninstall 3.9.X pyenv rehash -
Create a
symlinkat~/.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 -
If you wish to also include the
includedirectory, 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 -
Create
symlinksforidle,pip,pythonandwheelat 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 -
Once that’s done, run
pyenv rehashas recommended bypyenvwhenever you install new versionspyenv rehash -
Now, you’re ready to verify all versions managed by
pyenv, and select aglobal,local, orshellversion$ pyenv versions * system (set by /Users/cesarcoatl/.pyenv/version) 2.7.18 3.9 -
If you want to set
3.9as global, just run by runningpyenv global 3.9 -
Verify your selection by running
$ pyenv versions system 2.7.18 * 3.9 (set by /Users/cesarcoatl/.pyenv/version) -
And now when I run
python --versionI get the following output:$ python --version Python 3.9.6
And that’s it! You’ve done it!
Thanks for reading and happy coding!