[英]Installed Python 3 on Mac OS X but its still Python 2.7
[英]Installed Python 3.9.1 onto MAC OS but still says Python version is 2.7
我在我的 MacBook 上安裝了 Python 3.9.1,但是當我使用命令 python --version 時,它顯示它的 python 2.7。 這是我的終端中發生的事情以供參考:
$ python -V
Python 2.7.16
$ brew install pyenv
Updating Homebrew...
==> Auto-updated Homebrew!
Updated Homebrew from 565becc90 to e41981a5c.
Updated 1 tap (homebrew/core).
==> New Formulae
htmltest mpdecimal vitess
==> Updated Formulae
Updated 158 formulae.
==> Homebrew was updated to version 2.7.7
The changelog can be found at:
https://github.com/Homebrew/brew/releases/tag/2.7.7
Warning: pyenv 1.2.22 is already installed and up-to-date.
To reinstall 1.2.22, run:
brew reinstall pyenv
$ pyenv install 3.9.1
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.9.1.tar.xz...
-> https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tar.xz
Installing Python-3.9.1...
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
Installed Python-3.9.1 to /Users/myname/.pyenv/versions/3.9.1
$
$ python --version
Python 2.7.16
在此先感謝您的幫助!
我在我的 MacBook 上安裝了 Python 3.9.1 但是當我使用命令 python --version 時,它說它的 python 2.7。 這是我的終端中發生的事情以供參考:
$ python -V
Python 2.7.16
$ brew install pyenv
Updating Homebrew...
==> Auto-updated Homebrew!
Updated Homebrew from 565becc90 to e41981a5c.
Updated 1 tap (homebrew/core).
==> New Formulae
htmltest mpdecimal vitess
==> Updated Formulae
Updated 158 formulae.
==> Homebrew was updated to version 2.7.7
The changelog can be found at:
https://github.com/Homebrew/brew/releases/tag/2.7.7
Warning: pyenv 1.2.22 is already installed and up-to-date.
To reinstall 1.2.22, run:
brew reinstall pyenv
$ pyenv install 3.9.1
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.9.1.tar.xz...
-> https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tar.xz
Installing Python-3.9.1...
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
Installed Python-3.9.1 to /Users/myname/.pyenv/versions/3.9.1
$
$ python --version
Python 2.7.16
在此先感謝您的幫助!
如果您已安裝 python 他們 brew 然后編輯 your.zprofile
添加這一行 export PATH=/usr/local/opt/brew/opt/python@3.9/libexec/bin:$PATH
列出 bin 下的所有 python
ls -l /usr/local/bin/python*
這樣的事情將被列出
lrwxr-xr-x 1 ali admin 24 Dec 28 22:27 /usr/local/bin/python3 -> /usr/local/bin/python3.9
lrwxr-xr-x 1 ali admin 39 Mar 31 2022 /usr/local/bin/python3 -> ../Cellar/python@3.9/3.9.12/bin/python3
lrwxr-xr-x 1 ali admin 46 Mar 31 2022 /usr/local/bin/python3-config -> ../Cellar/python@3.9/3.9.12/bin/python3-config
lrwxr-xr-x 1 ali admin 41 Mar 31 2022 /usr/local/bin/python3.9 -> ../Cellar/python@3.9/3.9.12/bin/python3.9
lrwxr-xr-x 1 ali admin 48 Mar 31 2022 /usr/local/bin/python3.9-config -> ../Cellar/python@3.9/3.9.12/bin/python3.9-config
然后將符號鏈接更改為 3.9 或者你的新版本
ln -s -f /usr/local/bin/python3.9 /usr/local/bin/python
退出終端並重新啟動它,它現在應該可以工作了,通常你還必須更改 pip 的符號鏈接,因為它在 python3 目錄下。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.