為 NI TestStand 安裝 Python

更新 Dec 23, 2024

環境

軟體

  • TestStand

程式語言

  • Python

如果您想在 NI TestStand 中使用 Python 步驟,您首先需要安裝 Python。下載 Python 後,您將進行自訂安裝以準備在 NI TestStand 中找到 Python。

本文會說明如何為 NI TestStand 2024 Q4 安裝 Python。對於較舊(或較新)的 NI TestStand 版本,只需稍作調整還是可遵循此流程進行。

Python Step 最早在 NI TestStand 2019 中開始支援,請參閱從 NI TestStand 呼叫腳本語言

下載Python

1. 使用下表確定您的 NI TestStand 版本支援的 Python 版本。

支援的 Python Adapter:

NI TestStand 版本支援的Python版本
2024 Q43.8、3.9、3.10、3.11、3.12
2023 Q43.8、3.9、3.10、3.11
2022 Q43.7、3.8、3.9、3.10
2021 SP13.6、3.7、3.8、3.9、3.10



2. 下載Python 的 Windows 安裝程式

安裝Python

1. 執行Python安裝程式。

2. 確保選取「Add python.exe to PATH」勾選框,這麼做是為了讓 TestStand 能找到 Python 直譯器,所以我們需要將 Python 加入PATH 環境變數。

3. 選擇自訂安裝

01_定制安裝.png

4. 在進階選項設定中:

  • 為所有使用者啟用安裝
  • 安裝在「C:\Program Files」或「C:\Program Files (86)」以外的位置,如下所示。

    02_定制安裝.png


在 TestStand 中設定 Python Adapter

1. 在 Teststand 檔案選單中,點擊 Configure >> Adapters… >> Python >> Configure… 

2. 選擇您安裝的Python版本。

03_Python版本.png

3. 視您的需要來要勾選 Display console for interpreter sessions.

注意:如果您選取 Display console for interpreter sessions ,則在Adapter呼叫期間將開啟控制台視窗,並且將顯示 print() 命令。通常建議不要選取此核取方塊進行佈署,因為那樣您將需要手動處理控制台彈出視窗。另請記住,不要手動關閉控制台視窗 - 如果這樣做,Python Adapter將會crash,並且您需要先Unload all modules  然後才能再次使用 Python Adapter。

4. 您可能會想要使用virtualenv來使用虛擬環境。請參閱知識library文章 TestStand 的 Python Adapter設定顯示無效的虛擬環境路徑,以了解更多資訊。

有關 Python Adapter設定的更多資訊,請參閱NI TestStand 幫助 >> Python Adapter


完成

您已完成 NI TestStand 的 Python 安裝。您可以在下面的相關連結部份找到 TestStand 步驟的 Python 範例。

下一步