简体   繁体   English

macOS BigSur 上 python 版本的问题

[英]Problems with the python version on macOS BigSur

I have a problem with the python version.我的python版本有问题。 I downloaded and installed the latest version of python directly from the site, 3.9.0, but when I check the version from the terminal using the python --version command, 2.7.16 is installed and installing the PIP package manager I get this in response:我直接从站点下载并安装了最新版本的 python,3.9.0,但是当我使用 python --version 命令从终端检查版本时,安装了 2.7.16 并安装了 PIP 包管理器,我得到了这个回复:

DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Defaulting to user installation because normal site-packages is not writeable
Collecting pip
Downloading pip-20.2.4-py2.py3-none-any.whl (1.5 MB)|████████████████████████████████| 1.5 MB 1.7 MB/s 
Installing collected packages: pip

WARNING: The scripts pip, pip2 and pip2.7 are installed in '/Users/user/Library/Python/2.7/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-20.2.4

[edit] (thanks to @JohnVargo) [编辑](感谢@JohnVargo)
Big Sur uses zsh by default, therefore you must amend the .zprofile i/o the .bash_profile . Big Sur默认使用zsh ,因此您必须修改.zprofile i/o .bash_profile ...Unless you changed the default to use bash , then do as follows: ...除非您将默认值更改为使用bash ,否则请执行以下操作:
[/edit] [/编辑]


If you want to use python to launch python3 from the command line, you can go to your home directory and edit your ~/.bash_profile by adding the following lines:如果您想使用python从命令行启动python3 ,您可以转到您的主目录并通过添加以下行来编辑您的~/.bash_profile

in terminal type $ which python this will return the path to the system python2 interpreter;在终端类型$ which python这将返回系统python2解释器的路径; let's call this path_to_p2让我们称之为path_to_p2

in terminal type $ which python3 this will return the path to the system python3 interpreter;在终端类型$ which python3这将返回系统python3解释器的路径; let's call this path_to_p3让我们称之为path_to_p3

export PATH=path_to_p3:$PATH
alias python3=path_to_p3
alias python=path_to_p3

export PATH=path_to_p2:$PATH
alias python2=path_to_p2

save, relaunch terminal;保存,重新启动终端; You can now launch python3 with either python , or python3 , and python2 with python2您现在可以使用pythonpython3启动python3 ,使用python2 python2

This is because macOS uses python 2 by default.这是因为 macOS 默认使用 python 2。 So run your commands with python3 Then it'll only use python 3.所以用python3运行你的命令然后它只会使用 python 3。

在此处输入图片说明

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM