Python 2.x 3.x 共存

d.l.spm
4 min readJun 1, 2020

--

python2 | python3 | pip | pip3

src : https://docsplayer.com/172170830-Python-python-dgut-python-python-40.html
  • 安裝
  • pip

安裝

  • 官網載點
  • exe 改名
  • 環境變數

官網載點

我選擇
Python 3.8.3 | Python 2.7.18

安裝詳細過程請參考

exe 改名

Python38

  • 複製 →python.exe → 重新命名為 python3.exe
  • 複製 →pythonw.exe → 重新命名為 pythonw3.exe

Python27

  • 複製 → python.exe → 重新命名為 python2.exe
  • 複製 →pythonw.exe → 重新命名為 pythonw2.exe

環境變數

路近 : 本機右鍵\內容\進階系統設定\環境變數

系統變數\Path

新增以下(請依照自己的路徑跟資料夾名稱)

  • 若當初安裝時有勾選 Add Python x.x to PATH 就會有了

測試

開啟 CMD 命令提示字元(搜尋 cmd)

python
python2
python3

python2 → python2.exe | python3 → python3.exe

環境變數 python 順序決定 python 是 python2 還是 python3

pip

pip 是我們下載插件的方法

檢查版本

pip3 -V
pip -V
pip2 -V
由上圖可知道透過不同pip 下載的插件會到哪個 python 環境底下

所以別再不知道要使用 pip 還是 pip3 了,決定於當下運行的是在哪個 python 環境底下,就使用相對應的 pip

升級 pip

pip install --user --upgrade pip

ModuleNotFoundError: No module named ‘pip’

python -m ensurepip
python -m pip install --upgrade pip

--

--

d.l.spm
d.l.spm

No responses yet