2026年6月17日 星期三

MSI 電競桌機維修 (四)

今天的進度是要安裝 Windows 命令列軟體包管理工具 Scoop, 並利用它來安裝全域 Python 執行環境. 兩年前此主機到貨後, 我是直接到官網下載最新版 Python 來安裝, 但隨後要安裝 Stable Diffusion 時卻發現系統 Python 版本太新而卡關, 所幸後來找到自帶 Python 的一鍵安裝版才解決. 

這次我先跟 Gemini 討論要怎樣布置執行環境才好, 它建議先用 Scoop 安裝最新版的 Python 作為系統全域執行環境 (Thonny 解譯器可掛接到此執行環境); 然後再用 MiniConda 來安裝特定版本的 Python (例如跑 Stable Diffusion 要用的 Python 10.11).  

本系列之前的文章參考 :



1. 安裝 Scoop 工具 : 

Scoop 是一個類似 Mac 系統的 Homebrew 的 Windows 命令列軟體管理工具, 可以在系統中安裝並切換不同版本的 Python 執行環境, 但它是全系統切換的淺層隔離架構, 一次只能切換一個主控版本作為全域 Python 執行環境. 除了用來安裝與管理 Python 版本, 它還可以用來安裝 uv, nvm, git 等套件軟體, 架構如下圖所示 : 


 

開啟 Power Shell 視窗, 先用下列設定 PowerShell 視窗腳本執行原則 :

PS C:\WINDOWS\System32> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser   

然後才能用下列指令安裝 Scoop :

PS C:\WINDOWS\System32> Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression     
Initializing...
Downloading...
Extracting...
Creating shim...
Adding ~\scoop\shims to your path.
Scoop was installed successfully!
Type 'scoop help' for instructions.


2. 用 Scoop 安裝 Python : 

Scoop 管理 Python 版本的方式 是透過將 ~/scoop/shims 資料夾加入到系統 PATH 中, 並將 python 指令連結到此資料夾的一個 "捷徑" 以達成版本切換功能, 此 "捷徑" 實際上用是一個類似連結功能的墊片程式 ~/scoop/shims/python.exe 將 python 指令轉發給目標版本的 python.exe 程式. 

與 Python 相關的常用 scoop 指令如下表 :


 常用 Scoop 指令  說明
 scoop bucket add versions  訂閱 Scoop 的 versions 軟體庫 (執行一次即可)
 scoop search python  搜尋可安裝的 Python 版本
 scoop install python311  安裝指定版本的 Python (需先訂閱 versions 軟體庫)
 scoop install python  安裝 Scoop 目前 versions 軟體庫的最新穩定版 Python
 scoop list  顯示 Scoop 已安裝的 Python 版本
 scoop reset python3xx  切換到指定 Python 版本
 scoop update python  將 Python 升級到 versions 軟體庫最新版


注意, Scoop 軟體庫裡的最新版可能與 Python 官網有短暫時差. 其次, 用 scoop install python 安裝的 Python 版本, 未來用 scoop update python 指令更新時會追逐最新版, 例如從 v3.12 提升至 v3.13 (舊的 v3.12 就會被覆蓋或移除); 若用 scoop install python312 安裝, 則 scoop update python 只會升級 3.12 的小修補版本 (例如 3.12.1 升到 3.12.2), 不會跨代升級到 v3.13. 

另外, Scoop 在安裝好預設就已經訂閱了內建的 Main 軟體庫, 追逐最新版的 python 套件就放在 Main 裡面, 直接下 scoop install python 就可安裝. 特定舊版本則是放在 versions 軟體庫, 只有當要安裝非最新版的歷史版本或特定代號版時, 才需要先執行 scoop bucket add versions 訂閱 versions 軟體庫後再安裝. 

我想讓此主機的系統 Python 追逐最新版, 所以直接安裝 python 套件即可 : 

PS C:\WINDOWS\System32> scoop install python 
Installing 'dark' (3.14.1) [64bit] from 'main' bucket
dark-3.14.1.zip (5.0 MB) [====================================================================================] 100%
Checking hash of dark-3.14.1.zip ... ok.
Extracting dark-3.14.1.zip ... done.
Linking ~\scoop\apps\dark\current => ~\scoop\apps\dark\3.14.1
Creating shim for 'dark'.
'dark' (3.14.1) was installed successfully!
Installing 'python' (3.14.6) [64bit] from 'main' bucket
python-3.14.6-amd64.exe (29.3 MB) [===========================================================================] 100%
Checking hash of python-3.14.6-amd64.exe ... ok.
Running pre_install script...done.
Running installer script...done.
Linking ~\scoop\apps\python\current => ~\scoop\apps\python\3.14.6
Creating shim for 'python3'.
Creating shim for 'idle'.
Creating shim for 'idle3'.
Adding ~\scoop\apps\python\current\Scripts to your path.
Adding ~\scoop\apps\python\current to your path.
Persisting Scripts
Persisting Lib\site-packages
Running post_install script...
done.
'python' (3.14.6) was installed successfully!
Notes
-----
Allow applications and third-party installers to find python by running:
reg import "C:\Users\tony1\scoop\apps\python\current\install-pep-514.reg"

可見目前 Scoop 的 main 軟體庫最新的 Python 版本是 v3.14.6, 與 Python 官網的一致. 檢視版本 :

PS C:\WINDOWS\System32> python --version   
Python 3.14.6
PS C:\WINDOWS\System32> python
Python 3.14.6 (tags/v3.14.6:c63aec6, Jun 10 2026, 10:26:10) [MSC v.1944 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.


3. 用 Scoop 安裝 uv : 

uv 工具是 Python 虛擬環境管理工具, 負責 Python 專案的區域隔離, 並提供 uv init 指令可自動建立 Python 專案結構, 比傳統的 venv + pip 作法更簡單好用. 從架構上看,  uv 與 scoop 可說是上下層或內外層關係, scoop 主外 (上), 負責外層基礎設施 (相當於大門管理員), 而 uv 主內 (下), 負責內層專案沙盒 (相當於每戶的管家), 參考 :


用 Scoop 安裝 uv 指令如下 : 

PS C:\WINDOWS\System32> scoop install uv   
Installing 'uv' (0.11.21) [64bit] from 'main' bucket
uv-x86_64-pc-windows-msvc.zip (22.4 MB) [=====================================================================] 100%
Checking hash of uv-x86_64-pc-windows-msvc.zip ... ok.
Extracting uv-x86_64-pc-windows-msvc.zip ... done.
Running installer script...Adding ~\scoop\persist\uv\python\shims to your path.
Adding ~\scoop\persist\uv\tools\shims to your path.
done.
Linking ~\scoop\apps\uv\current => ~\scoop\apps\uv\0.11.21
Creating shim for 'uv'.
Creating shim for 'uvx'.
Creating shim for 'uvw'.
Making C:\Users\tony1\scoop\shims\uvw.exe a GUI binary.
'uv' (0.11.21) was installed successfully!
Notes
-----
Scoop persists data since version 0.11.16. You may need to move data by yourself.
Before: '$env:APPDATA\uv', '$env:LOCALAPPDATA\uv'
After : 'C:\Users\tony1\scoop\persist\uv'

檢視版本 : 

PS C:\WINDOWS\System32> uv --version  
uv 0.11.21 (5aa65dd7a 2026-06-11 x86_64-pc-windows-msvc)


4. 用 Scoop 安裝 git : 

Git 是主流的版控軟體, 此外, 它所附的 git-bash 也可用來在 Windows 中作為執行 Claude Code 的介面, 參考 :


用 Scoop 安裝 git 指令如下 : 

PS C:\WINDOWS\System32> scoop install git     
Installing '7zip' (26.01) [64bit] from 'main' bucket
7z2601-x64.msi (1.9 MB) [=====================================================================================] 100%
Checking hash of 7z2601-x64.msi ... ok.
Extracting 7z2601-x64.msi ... done.
Linking ~\scoop\apps\7zip\current => ~\scoop\apps\7zip\26.01
Creating shim for '7z'.
Creating shim for '7zG'.
Making C:\Users\tony1\scoop\shims\7zg.exe a GUI binary.
Creating shim for '7zFM'.
Making C:\Users\tony1\scoop\shims\7zfm.exe a GUI binary.
Creating shortcut for 7-Zip\7-Zip File Manager (7zFM.exe)
Creating shortcut for 7-Zip\7-Zip Help (7-zip.chm)
Persisting Codecs
Persisting Formats
Running post_install script...done.
'7zip' (26.01) was installed successfully!
Notes
-----
To register the context menu entry, please execute the following command:
reg import "C:\Users\tony1\scoop\apps\7zip\current\install-context.reg"

If an error occurs while attempting to delete files during uninstallation, run the following command and then retry:
Stop-Process -Name 'explorer'
Installing 'git' (2.54.0) [64bit] from 'main' bucket
PortableGit-2.54.0-64-bit.7z.exe (56.3 MB) [==================================================================] 100%
Checking hash of PortableGit-2.54.0-64-bit.7z.exe ... ok.
Extracting PortableGit-2.54.0-64-bit.7z.exe ... done.
Running pre_install script...done.
Linking ~\scoop\apps\git\current => ~\scoop\apps\git\2.54.0
Creating shim for 'sh'.
Creating shim for 'git'.
Creating shim for 'git-bash'.
Making C:\Users\tony1\scoop\shims\git-bash.exe a GUI binary.
Creating shim for 'gpg'.
Creating shim for 'gpg-agent'.
Creating shim for 'gpgconf'.
Creating shim for 'gpg-connect-agent'.
Creating shim for 'pinentry'.
Making C:\Users\tony1\scoop\shims\pinentry.exe a GUI binary.
Creating shortcut for Git\Git Bash (git-bash.exe)
Creating shortcut for Git\Git CMD (git-cmd.exe)
Creating shortcut for Git\Git GUI (git-gui.exe)
Adding ~\scoop\apps\git\current\cmd to your path.
Running post_install script...done.
'git' (2.54.0) was installed successfully!
Notes
-----
To register file associations, please execute the following command:
reg import "C:\Users\tony1\scoop\apps\git\current\install-associations.reg"

To register the context menu entry, please execute the following command:
reg import "C:\Users\tony1\scoop\apps\git\current\install-context.reg"

To set Git Credential Manager Core for portable Git, please execute the following command:
git config --system credential.helper manager

檢視版本 :

PS C:\WINDOWS\System32> git --version  
git version 2.54.0.windows.1


5. 用 Scoop 安裝 nvm 工具 : 

安裝 Gemini CLI 與全端開發框架 Next.js 都要用到 Node.js, 其版本的管理使用 nvm 工具, 可以用 Scoop 來安裝 nvm, 指令如下 : 

PS C:\WINDOWS\System32> scoop install nvm   
Installing 'nvm' (1.2.2) [64bit] from 'main' bucket
nvm-noinstall.zip (6.0 MB) [==================================================================================] 100%
Checking hash of nvm-noinstall.zip ... ok.
Extracting nvm-noinstall.zip ... done.
Running pre_install script...done.
Linking ~\scoop\apps\nvm\current => ~\scoop\apps\nvm\1.2.2
Adding ~\scoop\apps\nvm\current to your path.
Adding ~\scoop\apps\nvm\current\nodejs\nodejs to your path.
Persisting nodejs
Persisting elevate.cmd
Persisting elevate.vbs
Persisting settings.txt
'nvm' (1.2.2) was installed successfully!
Notes
-----
You'll need to restart powershell/cmd to have it reload Environment Variables so nvm will work correctly

檢視版本 :

PS C:\WINDOWS\System32> nvm --version
1.2.2

安裝完須關閉 Power Shell 視窗重啟, 才能用它來安裝 Node.js.


6. 用 nvm 安裝 Node.js : 

nvm 工具可在電腦中安裝多個不同版本的 Node.js, 然後用 nvm use 指令啟用指定的版本 : 

PS C:\WINDOWS\System32> nvm install node  
26.3.0
Downloading node.js version 26.3.0 (64-bit)...
Extracting node and npm...
Complete
Installation complete.
If you want to use this version, type:

nvm use 26.3.0

啟用版本可指定版本號或直接用 node 表示最新版 : 

PS C:\WINDOWS\System32> nvm use node
26.3.0
Now using node v26.3.0 (64-bit)

檢視版本 : 

PS C:\WINDOWS\System32> node --version   
v26.3.0

這樣就可以用 Node.js 的 npm 指令來安裝 Node 的套件了. 

沒有留言 :