brew install python3
Add PATH to ~/.bash_profile and ~/.zshrc
export PATH=/usr/local/share/python:$PATH
If you see a permission error probably it is due to the fact that your site-packages directory (where pip is trying to install to) is protected and owned by an administrator.
You should not install any packages to the system version of Python and of course (almost) never use sudo forced installs for security reasons.
See
- https://www.bleepingcomputer.com/news/security/ten-malicious-libraries-found-on-pypi-python-package-index/; and
- https://stackoverflow.com/questions/46675670/permission-error-with-pip-python-3
Make sure you install Python using Homebrew, Python.org, or Canopy, which will leave the system Python alone. Example: python is the system python, python2 is Python version 2, and python3 is Python version 3. This also makes it more clear which version you are using. Also do not have a pip command - not on path - so you can't accidentally install something to system Python. Explicitly call pip2 or pip3. Using Homebrew Python will do all of this for you, so it's the most-favored recommendation of the many Python distributions available.