MacOS Python (version) chaos. shipped, MacPorts, official installer, anaconda
Soon after diving into python, I found out there were many versions of python co-existing in my MacOS, and I don't know how to manage them. It is a disaster for me.
After spending some time, here is what I found.
OS: macOS Catalina 10.15.3
- python installed by Apple:
- /usr/bin/python -> /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
may deprecate soon. - /usr/bin/python3
it is a stub if it is a fresh install, after full installation, it is v3.7.3.
- python installed by MacPorts:
- /opt/local/bin/python -> /opt/local/bin/python3.8
- /opt/local/bin/python3 -> /opt/local/bin/python3.8 =>
/opt/local/Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8 - /opt/local/bin/python2 -> /opt/local/bin/python2.7 =>
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 - I upgraded 3.7 to 3.8,
and set the path accordingly.
sudo port install python38
sudo port select --set python python38
sudo port select --set python3 python38export PATH=/opt/local/bin:/opt/local/sbin:/opt/local/libexec/gnubin:$PATH
I found out that anaconda is easier to manage and use, or virtualenv if you prefer.
- python installed by python.org installer
- /Library/Frameworks/Python.framework/Versions/3.8/bin/python3
Uninstalled. https://docs.python.org/3/using/mac.html?highlight=uninstall
I use Anaconda now.
- python installed by Anaconda
Anaconda is recommended for data science related development. Use virtualenv if you just need to manage python versions and library dependencies.
- /Users/xxx/anaconda3/bin/python (v3.7.x)
- conda cheat sheet:
activate default profile: conda activate
activate a custom profile : conda activate XXX
deactivate: conda deactivate
create a custom profile: conda create -n XXX python
create a custom profile with a specific python version: conda create -n XXX python=3.8.2
install libs for a profile: conda activate XXX; conda install pandas numpy jupyter
search available pkgs/version: conda search python; conda search 'python>3.8'
I treat every profile as a fresh installed python and use it both in VSCode and command line
Reference
- https://apple.stackexchange.com/questions/376077/is-usr-bin-python3-provided-with-macos-catalina/376079#376079?s=ac24ad47437c4b85b0546bc3c4f00f23
- https://gtbensmagazine.com/2019/05/07/the-right-and-wrong-way-to-set-python-3-as-default-on-macos/
- https://www.anaconda.com/distribution/
- https://github.com/conda/conda
Comments
Post a Comment