YOLOv5 學習 之 Windows 11 + Spyder開發環境架設篇

1. 安裝 Python

  • 前往 Python 官方網站,下載並安裝相容版本(如 3.9)。安裝時務必勾選「Add Python to PATH」!
  • 安裝完成後,開啟命令提示字元(cmd)輸入 python --version 驗證版本
    • 例外處理 – 若未顯示則手動編輯環境變數:搜尋 “環境變數”,在系統 PATH 新增 Python 安裝路徑(如 C:\Program File\Python39)和 Scripts 資料夾(如 C:\Program File\Python39\Scripts)。
  • 再來更新pip,命令提示字元(cmd)輸入 python.exe -m pip install --upgrade pip
  • 最後來安裝python環境管理套件uv,命令提示字元(cmd)輸入 “pip install uv安裝完成後,關閉命令提示視窗

2. 建立虛擬環境

  • 開啟命令提示字元(cmd),導航至專案資料夾(如C:\YOLOv5Project)
  • 建立Python 3.9.11虛擬環境,在命令提示字元(cmd),輸入 uv venv --python 3.9.11
    • 例外處理 – 如果出現“‘uv’ 不是內部或外部命令、可執行的程式或批次檔。”,在 Windows 11 上使用 pip 安裝 uv 後,命令提示字元無法識別 “uv”,因為 pip 預設安裝到用戶目錄 (c:\users\使用者\appdata\roaming\python\python39\site-packages),而非系統 PATH 路徑,因此需手動將用戶 Scripts 資料夾加入環境變數。
  • 啟用虛擬環境,在命令提示字元(cmd)輸入 .venv\Scripts\activate
    • 說明 – 正常開啟虛擬環境後,在命令提示視窗會出現”(YOLOv5Project) C:\YOLOv5Project>”

3. 安裝 PyTorch 與 CUDA 支援 (在虛擬環境下執行)

依電腦硬體來安裝適用的PyTorch,這個步驟要下載2G多的資料,整個過程約需 10-20 分鐘,視電腦與網路效能而定。

  • 有GPU用這個指令⇒ uv pip install torch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 –index-url https://download.pytorch.org/whl/cu118
  • 無GPU用這個指令⇒ uv pip install torch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2

4.下載並安裝 YOLOv5 (在虛擬環境下執行)

  • 開啟命令提示字元(cmd),導航至專案資料夾(如C:\YOLOv5Project)
  • 啟用虛擬環境,進行下載YOLOv5原始碼,在命令提示字元(cmd)輸入git clone https://github.com/ultralytics/yolov5.git
  • 下載完整後,進入 yolov5 資料夾,安裝依賴套件,整個過程約需 10-20 分鐘,視電腦與網路效能而定。
    • 安裝依賴套件(如 OpenCV、Matplotlib),在命令提示字元(cmd)輸入 uv pip install -r yolov5/requirements.txt

5. 安裝 Spyder IDE

  • 開啟命令提示字元(cmd),導航至專案資料夾(如C:\YOLOv5Project)
  • 啟用虛擬環境,下載YOLOv5原始碼,在命令提示字元(cmd)輸入uv pip install spyder

6. 設定Spyder IDE

  • 開啟命令提示字元(cmd):輸入spyder
  • 前往Tools > Preferences > Python Interpreter
  • 選擇"Use the following Python interpreter",瀏覽至虛擬環境的python.exe
    • 以此專案來說會需要設定到:”C:\YOLOv5Project.venv\Scripts\python.exe”
  • 套用並重啟Spyder,確認在IPython Console中輸入import sys; print(sys.executable)顯示環境路徑是否設定一致。

7. 使用Spyder測試 YOLOv5功能

  • 開啟命令提示字元(cmd):輸入spyder
  • 在Spyder中,執行detect.py
  • 無錯誤即安裝成功。

💡需安裝的windows軟體

  1. Python 3.9.11 下載點
    1. 安裝python後,需要更新pip,指令為python.exe -m pip install --upgrade pip
  2. git 下載點

💡需安裝的Python模組

  1. uv 套件管理程式
    1. pip install uv
  2. Spyder IDE
    1. uv pip install spyder
  3. PyTorch CUDA
    1. uv pip install torch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 --index-url https://download.pytorch.org/whl/cu118
  4. YOLOv5 下載並安裝相關依賴
    1. git clone https://github.com/ultralytics/yolov5.git
    2. uv pip install -r yolov5/requirements.txt

在〈YOLOv5 學習 之 Windows 11 + Spyder開發環境架設篇〉中有 26 則留言

  1. This article is phenomenal! I’ve been struggling with this exact challenge, and your post gave me both the understanding and the tools I needed to move forward. I love how you broke down each step and explained not just what to do but why it works. The troubleshooting section was also incredibly helpful – it’s clear you understand the common pitfalls people encounter. This is going straight to the top of my reference materials!

    回覆
  2. I’m often to blogging and i really appreciate your content. The article has actually peaks my interest. I’m going to bookmark your web site and maintain checking for brand spanking new information.

    回覆
  3. I’m often to blogging and i really appreciate your content. The article has actually peaks my interest. I’m going to bookmark your web site and maintain checking for brand spanking new information.

    回覆
  4. Really great read — I appreciate how clearly you explained the importance of local online presence for businesses today. It’s a topic many companies overlook, i find it very interesting and very important topic. can i ask you a question? also we are recently checking out this newbies in the webdesign industry., you can take a look . waiting to ask my question if allowed. Thank you

    回覆

發佈回覆給「Kaylin Mayo」的留言 取消回覆