How to link home brew python version and set it as default

后端 未结 10 604
春和景丽
春和景丽 2020-12-07 15:57

I just switched from MacPorts to HomeBrew. After installing all the required XCode versions and other software I tried installing python using homebrew: I think it successfu

相关标签:
10条回答
  • 2020-12-07 16:06

    On OS X High Sierra, I had to do this:

    sudo install -d -o $(whoami) -g admin /usr/local/Frameworks
    brew uninstall --ignore-dependencies python
    brew install python
    python --version # should work, returns 2.7, which is a Python thing (it's weird, but ok)
    

    credit to https://gist.github.com/irazasyed/7732946#gistcomment-2235469

    I think it's better than recursively chowning the /usr/local dir, but that may solve other problems ;)

    0 讨论(0)
  • 2020-12-07 16:07

    In the Terminal, type:

    brew link python
    
    0 讨论(0)
  • 2020-12-07 16:16

    The problem with me is that I have so many different versions of python, so it opens up a different python3.7 even after I did brew link. I did the following additional steps to make it default after linking

    First, open up the document setting up the path of python

     nano ~/.bash_profile
    

    Then something like this shows up:

    # Setting PATH for Python 3.7
    # The original version is saved in .bash_profile.pysave
    PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"
    export PATH
    
    # Setting PATH for Python 3.6
    # The original version is saved in .bash_profile.pysave
    PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
    export PATH
    

    The thing here is that my Python for brew framework is not in the Library Folder!! So I changed the framework for python 3.7, which looks like follows in my system

    # Setting PATH for Python 3.7
    # The original version is saved in .bash_profile.pysave
    PATH="/usr/local/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"
    export PATH
    

    Change and save the file. Restart the computer, and typing in python3.7, I get the python I installed for brew.

    Not sure if my case is applicable to everyone, but worth a try. Not sure if the framework path is the same for everyone, please made sure before trying out.

    0 讨论(0)
  • 2020-12-07 16:17

    After installing python3 with brew install python3 I was getting the error:

    Error: An unexpected error occurred during the `brew link` step
    The formula built, but is not symlinked into /usr/local
    Permission denied @ dir_s_mkdir - /usr/local/Frameworks
    Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks
    

    After typing brew link python3 the error was:

    Linking /usr/local/Cellar/python/3.6.4_3... Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks
    

    To solve the problem:

    sudo mkdir -p /usr/local/Frameworks
    sudo chown -R $(whoami) /usr/local/*
    brew link python3
    

    After this, I could open python3 by typing python3

    0 讨论(0)
  • 2020-12-07 16:17

    I think you have to be precise with which version you want to link with the command brew link python like:

    brew link python 3
    

    It will give you an error like that:

    Linking /usr/local/Cellar/python3/3.5.2... 
    Error: Could not symlink bin/2to3-3.5
    Target /usr/local/bin/2to3-3.5
    already exists. 
    

    You may want to remove it:

    rm '/usr/local/bin/2to3-3.5'
    

    To force the link and overwrite all conflicting files:

    brew link --overwrite python3
    

    To list all files that would be deleted:

    brew link --overwrite --dry-run python3
    

    but you have to copy/paste the command to force the link which is:

    brew link --overwrite python3
    

    I think that you must have the version (the newer) installed.

    0 讨论(0)
  • 2020-12-07 16:19

    If you used

    brew install python
    

    before 'unlink' you got

    brew info python
    /usr/local/Cellar/python/2.7.11
    
    python -V
    Python 2.7.10
    

    so do

    brew unlink python && brew link python
    

    and open a new terminal shell

    python -V
    Python 2.7.11
    
    0 讨论(0)
提交回复
热议问题