Upgrade auf Python 3.6 von Python 2.7 nicht möglich

Ich versuche, Python 2.7 zu entfernen und durch Python 3.6 zu ersetzen. Die Hauptsache, die ich tun möchte, ist, "python" einzugeben und mein Terminal verwendet Python 3.6, aber aus irgendeinem Grund werde ich daran gehindert, Python zu aktualisieren.

Ich habe Python 3 installiert mit:

brew install python3

Unten sind die Befehle, die ich ausführe. Würde mir bitte jemand weiterhelfen?

Guys-MacBook-Pro:bin guy$ python --version
Python 2.7.10

Guys-MacBook-Pro:bin guy$ python3 --version
Python 3.6.5

Guys-MacBook-Pro:bin guy$ whereis python
/usr/bin/python

Guys-MacBook-Pro:bin guy$ whereis python3

Guys-MacBook-Pro:bin guy$ pwd
/usr/bin

Guys-MacBook-Pro:bin guy$ ls -l | grep python
-rwxr-xr-x   1 root   wheel     66880 Mar 27 23:03 python
-rwxr-xr-x   4 root   wheel       925 Oct  7  2017 python-config
lrwxr-xr-x   1 root   wheel        75 Apr  2 15:56 python2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
lrwxr-xr-x   1 root   wheel        82 Apr  2 15:56 python2.7-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
-rwxr-xr-x   1 root   wheel     66880 Mar 27 23:03 pythonw
lrwxr-xr-x   1 root   wheel        76 Apr  2 15:56 pythonw2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2.7

Guys-MacBook-Pro:bin guy$ ls -l /usr/local/bin|grep python
lrwxr-xr-x  1 guy  admin  43 Apr 16 15:25 easy_install-3.6 -> ../Cellar/python/3.6.5/bin/easy_install-3.6
lrwxr-xr-x  1 guy  admin  31 Apr 16 15:25 pip3 -> ../Cellar/python/3.6.5/bin/pip3
lrwxr-xr-x  1 guy  admin  33 Apr 16 15:25 pip3.6 -> ../Cellar/python/3.6.5/bin/pip3.6
lrwxr-xr-x  1 root           wheel  69 Apr 16 12:42 python3 -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/python3
lrwxr-xr-x  1 root           wheel  76 Apr 16 12:42 python3-config -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/python3-config
lrwxr-xr-x  1 root           wheel  71 Apr 16 12:42 python3.6 -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6
lrwxr-xr-x  1 root           wheel  78 Apr 16 12:42 python3.6-config -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6-config
lrwxr-xr-x  1 root           wheel  72 Apr 16 12:42 python3.6m -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6m
lrwxr-xr-x  1 root           wheel  79 Apr 16 12:42 python3.6m-config -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6m-config
lrwxr-xr-x  1 guy  admin  33 Apr 16 15:25 wheel3 -> ../Cellar/python/3.6.5/bin/wheel3


Guys-MacBook-Pro:bin guy$ sudo ln -s /Library/Frameworks/Python.framework/Versions/3.6/bin/python3 python
ln: python: Operation not permitted

Guys-MacBook-Pro:bin guy$ sudo su

sh-3.2# pwd
/usr/bin

sh-3.2# ln -s /Library/Frameworks/Python.framework/Versions/3.6/bin/python3 python
ln: python: Operation not permitted

sh-3.2# exit
exit

Guys-MacBook-Pro:bin guy$ sudo su -

Guys-MacBook-Pro:~ root# cd /usr/bin

Guys-MacBook-Pro:bin root# ln -s /Library/Frameworks/Python.framework/Versions/3.6/bin/python3 python
ln: python: Operation not permitted

Guys-MacBook-Pro:bin root# 

Antworten (1)

Sie müssen nicht brew install python3mehr ausführen, um Python 3.x zu installieren, da die Formel pythonjetzt standardmäßig auf Python 3.x eingestellt ist. Einfach ausführen:

brew install python

um Python 3.x zu installieren.

Die von Homebrew installierte Python-Binärdatei heißt immer noch python3, daher pythonwird standardmäßig Apple Python ausgeführt, das immer noch Python 2.x ist. Um dies zu umgehen, alias pythonto , python3indem Sie Folgendes ausführen:

alias python="python3"

und es sollte den Trick tun. Möglicherweise möchten Sie die von Homebrew installierte python3Formel entfernen, indem Sie Folgendes ausführen:

brew uninstall python3

Warum nicht einfach das neueste (3.6.5) von python.org/downloads/mac-osx installieren
@Milliways Es ist völlig in Ordnung, es von der offiziellen Website herunterzuladen und zu installieren. OP wird jedoch über Homebrew installiert, daher ist die Antwort auf sein spezifisches Szenario zugeschnitten.