介紹如何在 Windows 安裝 Python 程式開發環境,撰寫並執行 Python 指令稿。
如果想要在 Windows 中撰寫 Python 指令稿(script)、開發 Python 的程式,首先第一步就是要先安裝 Python 的開發環境,以下是在 Windows 中安裝 Python 的步驟教學。
安裝 Python 程式開發環境
Step 1
首先到 Python 的官方網站下載 Python 的安裝檔,點選頁面中的「Download Python 3.X.X」即可立即下載。
![Python 官方網站 Python 官方網站](https://officeguide.cc/wp-content/uploads/2019/07/windows-python-installation-tutorial-20190716-01.png)
Step 2
下載 Python 的安裝檔後直接執行,點選「Install Now」即可開始安裝。
![安裝 Python 安裝 Python](https://officeguide.cc/wp-content/uploads/2019/07/windows-python-installation-tutorial-20190716-02.png)
對於會使用其他指令稿呼叫 Python 的進階使用者,可以考慮將 Python 加入 PATH
這個環境變數。
等待安裝過程,通常不用一分鐘就可以裝完了。
![安裝 Python 安裝 Python](https://officeguide.cc/wp-content/uploads/2019/07/windows-python-installation-tutorial-20190716-03.png)
Step 4
安裝完成後,點選「Close」即可關閉視窗。
![完成安裝 Python 完成安裝 Python](https://officeguide.cc/wp-content/uploads/2019/07/windows-python-installation-tutorial-20190716-04.png)
如果有需要靠命令列傳遞大量參數給 Python 程式的進階使用者,可以將 MAX_PATH
的長度限制解除。
Step 5
安裝完成後,就可以在 Windows 的開始選單中看到 Python 的相關項目,其中 IDLE 是一個整合性的執行與開發環境,可以方便開發者撰寫並測試 Python 指令稿。
![Windows 開始選單 Windows 開始選單](https://officeguide.cc/wp-content/uploads/2019/07/windows-python-installation-tutorial-20190716-05.png)
Step 6
開啟 IDLE 之後,會出現一個 Python Shell 視窗,在這裡可以直接輸入 Python 的程式碼,執行後立即查看結果。
![IDLE Python 執行環境 IDLE Python 執行環境](https://officeguide.cc/wp-content/uploads/2019/07/windows-python-installation-tutorial-20190716-06.png)
開發 Python 模組程式
Step 1
如果想要開發小型的 Python 程式,可以利用 IDLE 的程式碼編輯器,首先選擇「File」選單中的「New File」,開啟程式碼編輯器。
![新增檔案 新增檔案](https://officeguide.cc/wp-content/uploads/2019/07/windows-python-installation-tutorial-20190716-07.png)
Step 2
在 IDLE 程式碼編輯器中,撰寫自己的 Python 程式碼,然後儲存成 *.py
的模組指令稿。
![建立 Python 模組檔案 建立 Python 模組檔案](https://officeguide.cc/wp-content/uploads/2019/07/windows-python-installation-tutorial-20190716-08.png)
Step 3
選擇「Run」中的「Run Module」,即可立即執行這些程式碼。
![執行 Python 模組 執行 Python 模組](https://officeguide.cc/wp-content/uploads/2019/07/windows-python-installation-tutorial-20190716-09.png)
Step 4
執行時會開啟另外一個 Python Shell 視窗,顯示執行的結果。
![執行結果 執行結果](https://officeguide.cc/wp-content/uploads/2019/07/windows-python-installation-tutorial-20190716-10.png)
更改 IDLE 程式碼顏色
IDLE 的程式碼編輯器會自動幫 Python 的程式碼加上顏色,但預設是使用白色底的配色,如果想要改成深色底的樣式,可以從選項中調整。
Step 1
選擇「Options」的「Configure IDLE」。
![開啟 IDLE 設定 開啟 IDLE 設定](https://officeguide.cc/wp-content/uploads/2019/07/windows-python-installation-tutorial-20190716-11.png)
Step 2
選擇「Highlights」頁籤,調整「Highlighting Theme」的設定。
![更改 IDLE 程式碼配色 更改 IDLE 程式碼配色](https://officeguide.cc/wp-content/uploads/2019/07/windows-python-installation-tutorial-20190716-12.png)
Step 3
將配色改為深色底的樣式,眼睛看起來會比較舒服。
![IDLE 程式碼編輯視窗 IDLE 程式碼編輯視窗](https://officeguide.cc/wp-content/uploads/2019/07/windows-python-installation-tutorial-20190716-13.png)