DEV Community

Linlee
Linlee

Posted on

Easy to install Python -> Mac | Fix $PATH

1. Install homebrew

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Enter fullscreen mode Exit fullscreen mode

2.Install Pyenv

brew install pyenv pyenv-virtualenv
pyenv install -l
Enter fullscreen mode Exit fullscreen mode

3.Test pyenv

pyenv virtualenv 3.12.0 myproject

pyenv local myproject

pyenv virtualenv-delete my project
Enter fullscreen mode Exit fullscreen mode

4.Test python

$ python3 --version
Python 3.9.6
$ which -a python3
/usr/bin/python3
Enter fullscreen mode Exit fullscreen mode

==================================================
FIX Python not found in ZSH

Rus this

brew info python

Python has been installed as
  /opt/homebrew/bin/python3

Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
  /opt/homebrew/opt/python@3.11/libexec/bin
Enter fullscreen mode Exit fullscreen mode

Open profile config

nano ~/.bash_profile
Enter fullscreen mode Exit fullscreen mode

I use zsh and VS Code, so I ran this:

code ~/.zshrc
Enter fullscreen mode Exit fullscreen mode

Add the following lines to the file:

export PATH="/opt/homebrew/opt/python@3.11/libexec/bin:$PATH"
Enter fullscreen mode Exit fullscreen mode

Now reload the shell profile by running the following command:

source ~/.bash_profile

For zsh, you could use this:

source ~/.zshrc

Top comments (0)