1. Python2.7和3.5並存
1.1 安裝
安裝自不必多說,先裝2.7,再裝3.5.
說下安裝的目錄:Py3.5和Py2.7默認的安裝目錄是不一樣的,按默認的來就好,不用管。
Python2.7: C:\Python27
Python3.5: C:\Users\Administrator\AppData\Local\Programs\Python\Python35
1.2 環境變量
先安裝2.7再安裝3.5的好像是3.5的會替換到原來2.7添加到Path的路徑,所以要自己在手動添加2.7的。
1.3 改名
使用前,到 C:\Python27 將python.exe,pythonw.exe 改為python2.exe,pythonw2.exe
到C:\Users\Administrator\AppData\Local\Programs\Python\Python35 python.exe,pythonw.exe 改為python3.exe,pythonw3.exe
1.4 CMD進入對應的交互式界面
改完名后,就方便區分啟動了。
1.5 py文件指定版本運行
1.5.1 CMD命令行交互式
1.5.2 sublime指定版本運行
先按箭頭順序打開 untitled.sublime-build 編輯
分兩次操作,寫入如下代碼(根據自己的實際路徑和python名更改cmd命令和路徑,注意路徑是'\\'
# python2
#python2 { "cmd":["python2.exe", "-u", "$file"], "path":"C:\\Python27", "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)", "selector": "source.python" }
# python3
#python3 { "cmd":["python3.exe", "-u", "$file"], "path":"C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python35", "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)", "selector": "source.python" }
注意的時,儲存路徑(根據各位的實際情況來):C:\Users\Administrator\AppData\Roaming\Sublime Text 3\Packages\User
然后用Ctrl+B運行的時候,就在Tools-Build System中選擇相應的版本即可
如我要用python2運行就選擇如圖
2. pip的使用
2.1 安裝模塊
# python2
python2 -m pip install 模塊名
# python3
python3 -m pip install 模塊名
2.2 查看版本
# python2
python2 -m pip --version #pip 9.0.1 from C:\Python27\lib\site-packages (python 2.7)
# python3
python3 -m pip --version #pip 8.1.1 from C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages (python 3.5)
2.3 查看庫列表
# python2
python2 -m pip list
# python3
python3 -m pip list
python2查看list的時候,當提示如下:
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
解決方法:自己創建%APPDATA%\pip\pip.ini文件,添加如下文件內容:
[list]
format=columns
注:%APPDATA% 可以通過運行,輸入,回車進入
解決完,list由左邊變成右邊的