On the new MacOS 13 M1/M2, python 3.9 is pre-installed with pip3 (no pip). I don't install other Python versions with brew/macport or Python installer, only the pre-install 3.9.
With the pre-install python, the global site-package is located in
/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/site-packages (other installers will be
The per-user site-package is located in
When I pip3 install a package, it will be installed to the per-user location, not the global location, along with the executable files installed
~/Library/Python/3.9/bin. For example, after I upgrade pip3, pip will also be installed in
I want to run these executable files installed by pip3 without specifying the full path. When I upgraded pip3 the system still complained it couldn't find pip, and it took me some time to figure out why.
I can add
~/Library/Python/3.9/bin to PATH directly but I feel it is an ad hoc solution. For example, with the next macOS release, the pre-installed Python may upgrade to 3.10 (as that happened before) I may need to add
~/Library/Python/3.10/bin to PATH too. I have seen from time to time that
PATH is modified to be long and ugly just to include Python and the related executable files.
Should I set
~/Library/Python/3.9/bin and add PYTHONPATH to PATH? I would like to know what is the best practice for using
PYTHONPATH/PYTHONHOME for the pre-install python on Mac.
PYTHONPATH/PYTHONHOME are not set by default.
From What exactly should be set in PYTHONPATH?, the agreed-upon answers are that I don't need to set PYTHONPATH unless there are non-standard libraries I want to use. But these answers seem not to solve my problem, of course, I need to use non-standard libraries for my development, say pytorch.
--- update ---
From the comments I got, I realized I installed python3 with
xcode-select --install, MacOS 13 doesn't preinstall python3.
Also from the comments let me reiterate my questions, 1. Should I set
PYTHONPATH/PYTHONHOME, why or why not? 2. I feel adding
~/Library/Python/3.9/bin to PATH is an ad hoc solution and I would like to know if is there a better way.
Of course, I need to add those executables' paths to the PATH in the end. But I didn't know the correct usage of PYTHONPATH so I thought maybe I could add those executables' paths to PYTHONPATH and then add PYTHONPATH to PATH. In that way when I have more paths to add, I just need to edit PYTHONPATH and PATH remains the same.
But that seems not to be the proper usage of PYTHONPATH from what I have so far.