如何链接home brew python版本并将其设置为默认值

时间:2022-10-14 00:24:19

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 successfully installed, but when I do which python it still shows me 2.7.3 which I think is the version shipped with Mountain Lion.

我刚从MacPorts切换到HomeBrew。在安装了所有必需的XCode版本和其他软件之后,我尝试使用自制软件安装python:我认为它已成功安装,但是当我执行哪个python时它仍然显示2.7.3我认为是Mountain Lion附带的版本。

which python
/usr/local/bin/python

python --version
Python 2.7.3

so I tried to install again

所以我试着再次安装

brew install python --framework --universal
Warning: python-2.7.5 already installed, it's just not linked

But it says python 2.7.5 already install and not linked, I tried to do brew link python

但是它说python 2.7.5已经安装而没有链接,我试着做brew链接python

That led me to following message so, I have no idea what I should be doing:

这导致我跟随消息,所以,我不知道我应该做什么:

Linking /usr/local/Cellar/python/2.7.5... Warning: Could not link python. Unlinking...

链接/usr/local/Cellar/python/2.7.5 ...警告:无法链接python。取消链接...

Error: Could not symlink file: /usr/local/Cellar/python/2.7.5/bin/smtpd2.py
Target /usr/local/bin/smtpd2.py already exists. You may need to delete it.
To force the link and overwrite all other conflicting files, do:
  brew link --overwrite formula_name

To list all files that would be deleted:
  brew link --overwrite --dry-run formula_name

7 个解决方案

#1


12  

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

使用brew install python3安装python3之后我收到错误:

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:

键入brew链接python3后,错误是:

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 ????

在此之后,我可以通过输入python3 to打开python3

(From https://github.com/Homebrew/homebrew-core/issues/20985)

#2


6  

In the Terminal, type:

在终端中,键入:

brew link python

#3


6  

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

并打开一个新的终端shell

python -V
Python 2.7.11

#4


3  

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

我想你必须准确地说明你要用命令brew link python链接哪个版本,如:

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.

我认为您必须安装版本(较新版本)。

#5


3  

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

在OS X High Sierra上,我不得不这样做:

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

信用到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 ;)

我认为这比递归chowning / usr / local dir更好,但这可能会解决其他问题;)

#6


2  

brew switch to python3 by default, so if you want to still set python2 as default bin python, running:

brew默认切换到python3,所以如果你还想把python2设置为默认的bin python,运行:

brew unlink python && brew link python2 --force

#7


0  

This answer is for upgrading Python 2.7.10 to Python 2.7.11 on Mac OS X El Capitan . On Terminal type:

这个答案是在Mac OS X El Capitan上将Python 2.7.10升级到Python 2.7.11。在终端类型:

brew unlink python

After that type on Terminal

在终端上的那种类型之后

brew install python

#1


12  

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

使用brew install python3安装python3之后我收到错误:

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:

键入brew链接python3后,错误是:

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 ????

在此之后,我可以通过输入python3 to打开python3

(From https://github.com/Homebrew/homebrew-core/issues/20985)

#2


6  

In the Terminal, type:

在终端中,键入:

brew link python

#3


6  

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

并打开一个新的终端shell

python -V
Python 2.7.11

#4


3  

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

我想你必须准确地说明你要用命令brew link python链接哪个版本,如:

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.

我认为您必须安装版本(较新版本)。

#5


3  

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

在OS X High Sierra上,我不得不这样做:

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

信用到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 ;)

我认为这比递归chowning / usr / local dir更好,但这可能会解决其他问题;)

#6


2  

brew switch to python3 by default, so if you want to still set python2 as default bin python, running:

brew默认切换到python3,所以如果你还想把python2设置为默认的bin python,运行:

brew unlink python && brew link python2 --force

#7


0  

This answer is for upgrading Python 2.7.10 to Python 2.7.11 on Mac OS X El Capitan . On Terminal type:

这个答案是在Mac OS X El Capitan上将Python 2.7.10升级到Python 2.7.11。在终端类型:

brew unlink python

After that type on Terminal

在终端上的那种类型之后

brew install python