在電腦上安裝了Python2.7和Python3.8,都是通過下載www.python.org中的安裝文件安裝完成的。
Win10系統,Thinkpad E480筆記本電腦。
安裝完成,僅有各自目錄下的
D:\python27\
D:\python3\python38\
各自目錄下都有一個python.exe和pythonw.exe。
安裝完後,在環境變量path中已經有
D:\python3\python38\和D:\python3\python38\Scripts。
手動把D:\python27\和D:\python27\Sripts也添加了進去。
在命令行執行Python -V時,是3.8.0版本。
上網搜了搜,有方法是把可執行文件的名字給改掉。有點不爽。
找了找IDLE命令行的命令,發現是在libs\idlelib\下的IDLE.bat來實現的。
python27的idle.bat
@echo off
rem Working IDLE bat for Windows - uses start instead of absolute pathname
start idle.pyw %1 %2 %3 %4 %5 %6 %7 %8 %9
意思是關閉回顯,註釋,啓動同目錄下的idle.pyw,雙擊idle.bat,沒有反應。
同樣看了看python38的idle.bat
@echo off
rem Start IDLE using the appropriate Python interpreter
set CURRDIR=%~dp0
start "IDLE" "%CURRDIR%..\..\pythonw.exe" "%CURRDIR%idle.pyw" %1 %2 %3 %4 %5 %6 %7 %8 %9
意識是關閉回顯,註釋,設置CURRDIR變量,啓動pythonw.exe來執行idle.pyw。
雙擊idle.bat,可以出現python 3.8.0的IDLE命令行。
python2.7的IDLE不能執行,估計是path的順序問題導致的,調用的是python3.8的可執行文件。
想是否可以用python3.8的idle.bat代替python2.7的idle.bat。
拷貝start "IDLE" "%CURRDIR%..\..\pythonw.exe" "%CURRDIR%idle.pyw" %1 %2 %3 %4 %5 %6 %7 %8 %9到python2.7的IDLE,真的可以執行。
把各自的IDLE.bat添加到桌面快捷方式,就解決了。