1. 程式人生 > 其它 >DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020.

DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020.

技術標籤:pythonopencv

將mac預設的Python2.7改為Python3

鑑於mac預設的python環境為2.7,而pip在安裝的時候會提示Python 2.7 reached the end of its life on January 1st, 2020.,因此我們需要更改執行環境。

  1. 輸入:
which python

返回python2.7的地址,我們可以用這個地址+’-V’的形式得到具體版本,如我python2.7地址為/usr/bin/python,我輸入

/usr/bin/python`-V

返回
Python 2.7.16。

  1. 類似操作,得到Python3的地址
which python3

返回

/usr/bin/python3
  1. 接下來我們寫一個配置檔案:
vi ~/.bash_profile

i進入插入模式,往裡面寫入,這個取決於你python3的具體位置。

PATH="/usr/bin:${PATH}"
export PATH
alias python="/usr/bin/python3"

然後按:wq退出。

  1. 之後我們每次希望時候python3環境的時候,就先輸入:
source ~/.bash_profile

然後輸入python執行的就是python3的環境了。
在這裡插入圖片描述

換言之,此時我們用pip安裝的就是在python3下安裝的。
如下是安裝opencv的方法

source ~/.bash_profile
pip3 install opencv-contrib-python