简体   繁体   English

在 MAC OS 上安装了 Python 3.9.1 但仍然说 Python 版本是 2.7

[英]Installed Python 3.9.1 onto MAC OS but still says Python version is 2.7

I installed Python 3.9.1 onto my MacBook however when I use the command python --version it says its python 2.7.我在我的 MacBook 上安装了 Python 3.9.1,但是当我使用命令 python --version 时,它显示它的 python 2.7。 Here's what going on in my terminal for reference:这是我的终端中发生的事情以供参考:

$ 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

Thanks in advance for your help!在此先感谢您的帮助!

I installed Python 3.9.1 onto my MacBook however when I use the command python --version it says its python 2.7.我在我的 MacBook 上安装了 Python 3.9.1 但是当我使用命令 python --version 时,它说它的 python 2.7。 Here's what going on in my terminal for reference:这是我的终端中发生的事情以供参考:

$ 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

Thanks in advance for your help!在此先感谢您的帮助!

If you have install python they brew then edit your.zprofile如果您已安装 python 他们 brew 然后编辑 your.zprofile

add this line export PATH=/usr/local/opt/brew/opt/python@3.9/libexec/bin:$PATH添加这一行 export PATH=/usr/local/opt/brew/opt/python@3.9/libexec/bin:$PATH

list all python under bin列出 bin 下的所有 python

ls -l /usr/local/bin/python*

something like this will be listed这样的事情将被列出

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

then change the symlink to the 3.9 or what's new one for you然后将符号链接更改为 3.9 或者你的新版本

ln -s -f /usr/local/bin/python3.9 /usr/local/bin/python

Quit the terminal and start it again, it should work now, usually you have to change the symlink for pip too, cause it's under python3 directory.退出终端并重新启动它,它现在应该可以工作了,通常你还必须更改 pip 的符号链接,因为它在 python3 目录下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Mac OS X 上安装了 Python 3 但它仍然是 Python 2.7 - Installed Python 3 on Mac OS X but its still Python 2.7 如何在MAC OS中链接python 2.7和最新的openssl版本? - How to link python 2.7 with latest openssl version in MAC OS? MacPorts说当运行“python --version”时我仍然使用Python 2.7 - MacPorts says I still have Python 2.7 when “python --version” is run Python 的刽子手。 (版本:3.9.1) - Hangman with Python. ( version: 3.9.1 ) 安装了Python 3.7,并尝试将其更改为默认值,但是更改$ PATH并运行python --version仍显示2.7 - Installed Python 3.7 and tried changing that to the default however, changing $PATH and running python --version still shows 2.7 我在Mac上安装了python 2.7和3.6。 如何找到与Python3相关的pip版本? - I have python 2.7 and 3.6 installed on my mac. How to find the version of pip associated with Python3? 在Mac上已经安装了同时安装了Python 2.7和3.5的版本3.5.2中的Python模块 - Installing Python modules in version 3.5.2 with both Python 2.7 and 3.5 already installed on Mac 如何在安装了python 2.7的Mac上安装pygame? - How to install pygame on Mac with python 2.7 installed? 无法在 mac os 中卸载 python 2.7 - Unable to uninstall python 2.7 in mac os 在Mac OS Elcapitan中的python 2.7 paramiko问题 - issue with python 2.7 paramiko , in MAC OS Elcapitan
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM