---
# System prepended metadata

title: Python：安裝 python 並且添加環境變數
tags: [notes, tutorials, withhhsong, python]

---

# Python：安裝 python 並且添加環境變數

之前都是用 Anaconda 裡的 Spyder 跟 Jupyter Notebook 編譯 python，但 Anaconda 實在太過於佔用空間最後還是刪除了，改裝 VSCode（[VS code 與 wsl 安裝教學](https://withhhsong.com/python_wsl/)）。

## Download Python 下載並安裝

Python 官方載點：https://www.python.org/downloads/

![](https://i.imgur.com/hKDG48L.png)

選中你要的版本然後按 download 會跳進下一個頁面，找到符合你作業系統的版本然後按下去就可以下載了。我是下載 64 位元的 Windows Installer 版本。

![](https://i.imgur.com/1rHqcsE.png)

![](https://i.imgur.com/8U3wbok.png)

我是安裝 python 版本 3.10 在這個路徑上：

```=shell
C:\Users\user\AppData\Local\Programs\Python\
```

![](https://i.imgur.com/2hAjjmB.png)


## 添加 Python 路徑到環境變數 Path 中

先打開環境變數，可以在工具列的搜尋上查找「環境變數」。

### 系統 > 進階系統設定 > 環境變數

![](https://i.imgur.com/0y4yDuv.png)

![](https://i.imgur.com/fUV0aAE.png)

### 選中系統變數的 Path 欄位按編輯

![](https://i.imgur.com/nNl09iS.png)


### 新增剛才安裝 python 的路徑位置如下

```=shell
C:\Users\user\AppData\Local\Programs\Python\Python310
```
```=shell
C:\Users\user\AppData\Local\Programs\Python\Python310\Scripts
```
把這兩行路徑分別新增加入環境變數裡頭。

要看你的 python 安裝在哪裡，我的筆電預設是安裝在 Users 資料夾當中的 Local Programs，每台電腦安裝路徑並不完全相同。

### 測試：在 cmd 輸入 python

打開命令提示字元直接輸入 python，出現以下畫面代表安裝跟添加 python 執行路徑到環境變數是成功的了，以後就可以直接在 cmd 執行 python 檔案。

![](https://i.imgur.com/eDk8otF.png)

### 可能碰上的問題：cmd 執行 python 跑出 Microsoft Store

相關文章：[如何解決 cmd 執行 python 跑出 Microsoft Store](https://withhhsong.com/python_microsoft_store)

之前安裝好 python 並且確定有添加環境變數，但在命令提示字元裡執行 python 會一直跳轉到微軟商店，原因是 win10 有個奇怪的應用程式執行別名功能，輸入 python 或是 python3 就會自動幫你打開 Microsoft Store，無論有沒有安裝 python 都會莫名其妙自動導向。

解決辦法是打開設定，也可以直接在工具列上的搜尋上查找**管理應用程式執行別名**，把「應用程式執行別名」的 App Installer 功能關閉，就不會再自動跳轉了。

#### 設定 > 應用程式與功能 > 應用程式執行別名

![](https://i.imgur.com/RixJUTQ.png)

#### 把 App installer （python.exe） 關閉

![](https://i.imgur.com/CvYkrRq.png)

---

: : 20211115 : : 與松 withhhsong : :

###### tags: `notes` `python` `withhhsong` `tutorials`
