When I install the current release (3.11.5) of Python, I visit Python.org and download their installer. It is a Universal2 (X8 6_64, arm64) binary and normal macOS installer and will ask you for your administrator password, and then install the latest Python3 into these locations:
- /Library/Frameworks/Python.framework/Versions/3.11
- /usr/local/bin - these are the python3, pip3, idle3, etc linked from the first bullet bin directory
- /Applications/Python 3.11 folder
This installation is entirely independent of any Apple command line tools content, and steps on nothing in the operating system. I have this installed on Ventura 13.5.2 and the command line tools because I develop code in Swift or Objective-C (clang) compilers too.
You need to ensure that /usr/local/bin appears before /usr/bin in your PATH to avoid invoking Python 3.9.6. Once you have done that, then you can use the python3 commands in the Terminal and any pip3 installed modules will be installed into the first bullet tree hierarchy.
In your appropriate ˜/.zshrc or ˜/.bashrc or ~/.bash_profile:
export PATH=".:/usr/local/bin:/Library/Frameworks/Python.framework/Versions/3.11/bin:${PATH}"
After you save the relevant dot file above, you can either quit the Terminal or do the following to invoke the dot file where whatever is replaced by the specific dot file:
source ~/.whatever
After this PATH change, a python3 script should begin with the following to access /usr/local/bin/python3:
#!/usr/bin/env python3
and it can be run from the Terminal as whichever is appropriate:
python3 some.py
idle3 &
pip3 install -U pip