I have a separate installation of Python 3.*, but the first python path in my $PATH
variable is the path to system-installed Python. Is this how it should be?
I have added the path to user-installed Python using https://www.architectryan.com/2012/10/02/add-to-the-path-on-mac-os-x-mountain-lion/#.Uydjga1dXDg, and it was popped at the end of $PATH
.
Do I understand correctly that, in the current situation, when I run pip
, brew
etc. on python3 from bash, the changes will be applied to system-installed Python?
The fix I have got so far is to run export PATH=/usr/local/bin:/usr/local/sbin:$PATH
every time I want to install or
update python, but it is not ideal.
NB: I went with pyenv
solution as suggested by @bermudalocket. This pyenv tutorial was very useful.
Best Answer
You can accomplish this by adding
to your
~/.zshrc
(or~/.bash_profile
if you're not on Catalina).I'd like to propose an alternative and suggest
pyenv
, available via Homebrew. You can set a specific Python version to be "global" (i.e. default everywhere) and/or "local" (i.e. using that version in a specific directory only).E.g.:
If you were to use Python in
~/myProjects/MyProject
it will default to3.7.6
, and anywhere else2.7.16
:https://github.com/pyenv/pyenv#homebrew-on-macos