Homebrew not linking python correctly?

萝らか妹 提交于 2019-12-22 10:27:52

问题


I installed both python 2.7.13 and python 3.6.2 with homebrew and updated my ~/.bash_profile as such:

# Homebrew
export PATH=/usr/local/bin:$PATH

Python3 was linked fine. However, "which python" would still give me

/usr/bin/python

while "which python2" produces

/usr/local/bin/python2

It looks like homebrew installed python 2 as "python2" and never linked "python" to the new installation. This is causing me a lot of trouble down the road when installing virtualenvwrapper etc.

By the way, I also did brew link python.

Anybody know why this is and how to fix it?

Much appreciated!!


回答1:


They change that behavior here

Today I’d like to announce Homebrew 1.3.0. The most significant change since 1.2.0 is that brew install python no longer installs a python binary without manual PATH additions and instead installs a python2 binary. This avoids overriding the system python binary by default when installing Python as a dependency. It also paves the way to eventually have python be Python 3.x.

You will have to symlink python to the version of python installed by homebrew that you want.

You can do:

$ln -s /usr/local/bin/python2 /usr/local/bin/python

To symlink python to the homebrew Python2.x installation or do:

$ln -s /usr/local/bin/python3 /usr/local/bin/python

to link it to the Python 3.x hombrew installation.




回答2:


gsi-frank's solution solves the problem quite well but after using his solution, you might encounter problems with your pip3. Your pip3 might be linked to the old instance and therefore unusable for your new python instance.

Type which pip3 to see where your pip3's path. If your path is linked to your new instance, then ignore the rest of this answer.

Type echo $PATH to see your current path. If it contains your old python instance's path then you will need to remove it from your .bash_profile

To solve this: check your .bash_profile and see if there is a path to your old python instance. If the old path is in there, you can delete it.

I had this problem and here's a link to the question if needed: How to change pip3 path after installing python with homebrew?

To find your .bash_profile:

  • Go to your Finder
  • Right click and click Go to a folder... and type ~
  • Press CMD + shift + . to see hidden files
  • Right click your .bash_profile and open in a text editor


来源:https://stackoverflow.com/questions/45952921/homebrew-not-linking-python-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!