Python bundled with system files

Hello, I am new to MacOS, my whole life I was a PC person. Due to the fact that Apple is a standard in Data, I decided to switch.

I installed the latest Python3 from Python.org. However, Apple has python3 (3.9.6) and pip3 in the system files in usr/bin plus Apple stripped root of privileges which would allow to get rid of these executables.

The only way to run 3.11.x is to spell it out explicitly (python3.11). It would not be such big of a problem but there is a dependency with a number of packages and it creates a havoc with say jupyterlabs and jupyter notebook.

Any suggestions?


I hope I explained it alright. Thanks.

MacBook Pro 16″, macOS 13.3

Posted on May 11, 2023 06:11 AM

Reply

Similar questions

4 replies

May 11, 2023 07:25 AM in response to SeaLaurel

Since you installed Python 3.11.3 from Python.org, its binaries are located linked into /usr/local/bin. You can completely ignore the (optional) Command Line Tools for Xcode (or Xcode itself) installation of Python3 and pip3 in /usr/bin, and these cannot be removed as they are on a read-only System volume.


In your Shell startup files, either ~/.zshrc, or ~/.bash_profile, change your PATH statement:


export PATH=".:/usr/local/bin:/Library/Frameworks/Python.framework/Versions/3.11/bin:${PATH}"


From the Terminal, after the above PATH change, you can run the following to change the PATH in the current Terminal window where dotfile is either zshrc, bashrc, or bash_profile:


source ~/.dotfile


Now, when you run python3 or pip3, they completely ignore the older Apple python3 or pip3 and all third-party packages get installed in the correct site-packages location in that python.org distribution. If you installed any third-party packages using the Apple Python binaries, remove those packages, and after the above changes, reinstall those packages into the python3.11.3 distribution's site-packages using its pip3.


I go one step further and use python to create a virtual environment (venv) to isolate third-party packages to one filesystem location.


mkdir -p ~/py_projects
python3 -m venv ~/py_projects/env311
source ~/py_projects/env311/bin/activate && cd ~/py_projects/env311
pip3 install -U pip
pip3 install -U jupyterlab
pip3 install -U notebook
︙
deactivate  # when you are done with the venv
cd -        # back to the previous directory location


The Python3 version in this venv is updated when you apply any future Python 3.* updates from Python.org.

May 11, 2023 09:26 AM in response to VikingOSX

Thank you for the detailed reply, it is very helpful. One more little question. Possibly the one with an obvious answer :) which is not so obvious to me.


After I install a newer python3 version (3.12.x) in the future would I need to add another entry in PATH


:/Library/Frameworks/Python.framework/Versions/3.12/bin

or do I replace the old one?


Also my understanding is that even with virtual environments one cannot use different python versions in different venvs. Is that correct?


May 11, 2023 10:09 AM in response to SeaLaurel

You would just update the 3.11 in that PATH to 3.12, or if you were using both versions of Python3, then you would have two distinct library entries in your PATH varied by the version. But then, you would have to reference /usr/local/bin/python3.11, or /usr/local/bin/3.12 to access the appropriate library framework for that version.


Python3 virtual environments are based on the version of Python that created them, and there is only one /usr/local/bin/python3 based on the last installed distribution. However…


If you create version dependent virtual environments (venv) like so for Python 3.11.* and 3.12.*:


/usr/local/bin/python3.11 -m venv ~/py_projects/env311
/usr/local/bin/python3.12 -m venv ~/py_projects/env312


then subsequent updates to Python 3.11.* and 3.12.* will only update their respective version dependent virtual environments.


And just a note of clarification. Apple stopped bundling any Python2 distribution with macOS after Monterey 12.3, and never bundled Python3. The latter, at least from Apple, is only available via a current Xcode or Command Line Tools for Xcode installation.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Python bundled with system files

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.