Install Python 3 to /usr/bin/ on macOS

前端 未结 3 615
梦如初夏
梦如初夏 2021-02-15 17:36

I installed python2.x and python3.x using homebrew and the executable python paths are listed below:

$ which python
/Library/Frameworks/Python.framework/Versions         


        
3条回答
  •  心在旅途
    2021-02-15 18:10

    The basic question in the OP seems to not be doable because the newer Mac OSes have "System Integrity Protection" which prevents "unauthorized" changes to key directories such as /usr/bin, and sudo cannot override that.

    The suggestion of using /usr/local/bin and /usr/local/Frameworks seems like it should work (I haven't tried it). However, at https://opensource.com/article/19/5/python-3-default-mac, Matthew Broberg suggests that it is likely to create problems when updating.

    In that same article, Moshe Zadka recommends using pyenv to manage Python environments and using shell aliases rather than symlinks.

    I was going to go with the /usr/local suggestion above, but having found this contraindication, I'm going to try Moshe's method. I'll report back here if I hit any snags.

    Update: I followed the method and I still was getting pip not found and which python and python -V were not giving me the expected results. Doh! I ran:

    . ~/.bash_profile

    (where I had put the recommended eval "$(pyenv init -)" command) and suddenly everything was finding the paths and versions as expected.

提交回复
热议问题