1、python2.7和python3.5雙版本共存
1.1 安裝
將python2.7和python3.5直接安裝到C盤下:
python2.7:C:\Python27
python3.5:C:\Python35
1.2 環境變量配置
在path環境變量中添加一下四個變量,注意變量後記得加分號:
(1).C:\Python27
(2).C:\Python27\Scripts
(3).C:\Python35
(4).C:\Python35\Scripts
1.3 更名
進入python2.7安裝目錄,將python.exe、pythonw.exe 改名爲python2.exe、pythonw2.exe
進入python3.5安裝目錄,將python.exe、pythonw.exe 改名爲python3.exe、pythonw3.exe
1.4 測試
執行python2命令會進入python2.7的交互環境,執行python3命令會進入python3.5交互環境,說明到此爲止兩個版本的python算是安裝成功。需要注意的是,由於此前python.exe已改名爲python2.exe或python3.exe,所以再在cmd中輸入python命令無效。
2、pip的使用
在一個系統中共存python2、python3的時候,pip的使用應指定python版本。
2.1 安裝模塊
#python2
python2 -m pip install 模塊名
#python3
python3 -m pip install 模塊名
比如現在我要在一個python3.5版本下的項目用Pillow這個包。首先,project interperter指定python3.5是肯定的,然後在cmd中我們用 python3 -m pip install Pillow,然後等待下載就行了。同樣,在python2.7中替換爲python2就行。若是一開始沒有指定pyhton3,那麼每次用pip安裝Pillow包都會安裝到pyhton2.7版本下面。
2.2 查看pip版本
#python2
python2 -m pip --version
#python3
python3 -m pip --version
2.3 更新版本
#python2
python2 -m pip install --upgrade pip
#python3
python3 -m pip install --upgrade pip
2.4 查看庫列表
#python2
python2 -m pip list
#python3
python3 -m pip list