Homebrew python 2.7 vs OS X python 2.7

后端 未结 2 991
夕颜
夕颜 2021-01-06 17:39

this is my first time asking a question here so sorry in advance if I\'m doing something wrong. The problem is I installed python 2 using Homebrew to avoid using OS X system

相关标签:
2条回答
  • 2021-01-06 17:41

    Just go download and install new version any version of Python 2 or 3 for Mac

    and make sure you in the correct local (home) directory looks like

    compname:~ yourname$
    
    0 讨论(0)
  • 2021-01-06 18:01

    Homebrew recently changed the way it handles Python 2.x vs 3.x. It no longer shadows macOS’s python by default and instead installs Python 2.x as python2 and Python 3.x as python3.

    In fact, it does install python but doesn’t symlink it in /usr/local/bin, hence why your shell can’t find it. If you wish to get everything working as before you need to add it to your $PATH:

    export PATH="$(brew --prefix python)/libexec/bin:$PATH"
    

    You could also add an alias from python to python2 and from pip to pip2 but it’s a worse solution because you need one alias for each executable.

    # in your ~/.bash_profile
    alias python=python2
    alias pip=pip2
    

    Then start a new terminal session for the changes to take effect.

    See the official documentation for more info. This is also outlined in brew info python:

    $ brew info python
    python: stable 2.7.13, HEAD
    ...
    ==> Caveats
    This formula installs a python2 executable to /usr/local/bin.
    If you wish to have this formula's python executable in your PATH then add
    the following to ~/.bash_profile:
      export PATH="/usr/local/opt/python/libexec/bin:$PATH"
    
    Pip and setuptools have been installed. To update them
      pip2 install --upgrade pip setuptools
    
    You can install Python packages with
      pip2 install <package>
    
    They will install into the site-package directory
      /usr/local/lib/python2.7/site-packages
    ...
    
    0 讨论(0)
提交回复
热议问题