簡體   English   中英

macOS BigSur 上 python 版本的問題

[英]Problems with the python version on macOS BigSur

我的python版本有問題。 我直接從站點下載並安裝了最新版本的 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

[編輯](感謝@JohnVargo)
Big Sur默認使用zsh ,因此您必須修改.zprofile i/o .bash_profile ...除非您將默認值更改為使用bash ,否則請執行以下操作:
[/編輯]


如果您想使用python從命令行啟動python3 ,您可以轉到您的主目錄並通過添加以下行來編輯您的~/.bash_profile

在終端類型$ which python這將返回系統python2解釋器的路徑; 讓我們稱之為path_to_p2

在終端類型$ which python3這將返回系統python3解釋器的路徑; 讓我們稱之為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

保存,重新啟動終端; 您現在可以使用pythonpython3啟動python3 ,使用python2 python2

這是因為 macOS 默認使用 python 2。 所以用python3運行你的命令然后它只會使用 python 3。

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM