Pyinstaller打包pytest總結

2021-10-07 15:37:55 字數 1024 閱讀 7620

學習python也有一段時間了,最近有專案需求,需要對pytest打包,按照正常的打包流程,打包後,發現仍不能完整脫離環境執行,遂對pytest的pyinstaller打包方式進行了一些鑽研

python環境下,cmd輸入使用

pip install pyinstaller進行安裝

特別注意: 如果是預設源,建議切換為國內源

pyinstaller ***x.py    # 表示帶命令列多檔案打包

pyinstaller -f ***x.py # 帶命令列單檔案打包

pyinstaller -w ***x.py # 不帶命令列多檔案打包

pyinstaller -fw ***x.py # 不帶命令列單檔案打包

特別注意: 如果是帶資源檔案, 建議使用多檔案打包,或者使用其他引數帶資源檔案的單檔案打包

3.1 組織好pytest的專案工程

熟悉pytest的同學們知道,pytest是需要以test_***.py或者***_test.py的檔名來組成的,我們接下來的打包入口檔案就以這些檔案為準。

3.2 使用pyinstaller 進行打包

當我們使用pyinstaller test_***x.py進行pytest打包後,在執行exe時,會出現找不到用例的情況,此時我們需要將 test_***x.py放入打包後的資料夾

3.3 使用pyinstaller 對pytest的外掛程式打包

當我們使用到pytest的一些外掛程式(plugin),此時我們使用3.2中的步驟,仍然是不行的,此時就需要對打包資料夾做一些改動。

在網路上找了一圈發現,相關pytest 外掛程式打包方式還沒人發過帖子,所以故開此貼進行簡略講解。

此時我們只需要將外掛程式所在的原始碼包(通常在 site-packages 裡面的某個目錄),複製到打包後的資料夾,即可完成打包。

pyinstaller打包py檔案為exe方法

pip install pyinstallersuccessefully installed pip xx.xx.xx 安裝成功 2.打包python檔案 1.進入打包檔案所在資料夾,比如 cmd輸入 cd d d llk進入資料夾,入口檔案為run.py 2.打包檔案 在當前路徑下輸入 等待打包結...

pyinstaller打包py遇到的問題

遇到了幾個問題,記錄一下 ubuntu16.04系統 python3.6 conda 注意ubuntu的可執行檔案就直接是檔名,windows的可執行檔案是exe pip install pyinstaller然後直接 pyinstaller f 檔名.py在當前目錄下面有乙個dist資料夾 直接執...

pyinstaller打包程式

python打包成exe檔案時,用的是pyinstaller 第一步安裝pyinstaller pip install pyinstaller第二步 pyinstaller f w i ico py其中 ico 是logo,py是你要打包的py檔案 我在打包時出現了struct.error unpa...