项目包括whisper、pytorch、cuda、cudnn、chocolatey、ffmpeg、tkinterdnd2、tkinter、os、conda

项目包括whisper、pytorch、cuda、cudnn、chocolatey、ffmpeg、tkinterdnd2、tkinter、os、conda

希望将软件包分发给没有python,也没有打开cmd的能力的人使用。

安装chocolatey等系统级依赖,使用ps1脚本。

# 检查是否以管理员身份运行
function Test-Admin {
    $identity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
    $principal = [System.Security.Principal.WindowsPrincipal]$identity
    return $principal.IsInRole([System.Security.Principal.WindowsBuiltinRole]::Administrator)
}

if (-not (Test-Admin)) {
    Write-Host "This script must be run as an administrator." -ForegroundColor Red
    Start-Process powershell -ArgumentList "Start-Process PowerShell -ArgumentList 'Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString(''https://community.chocolatey.org/install.ps1''))' -Verb RunAs" -Verb RunAs
    exit
}

# 确保 Chocolatey 已安装
if (-not (Get-Command choco -ErrorAction SilentlyContinue)) {
    Write-Host "Chocolatey is not installed. Installing Chocolatey..." -ForegroundColor Yellow
    Set-ExecutionPolicy Bypass -Scope Process -Force
    [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
    iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
}

# 安装 Python 3.12 和 pip 工具
Write-Host "Installing Python 3.12 and pip..." -ForegroundColor Green
choco install python --version=3.12 --confirm

# 确保 pip 工具已安装
Write-Host "Ensuring pip is installed..." -ForegroundColor Green
python -m ensurepip

# 安装 FFmpeg
Write-Host "Installing FFmpeg..." -ForegroundColor Green
choco install ffmpeg --confirm

Write-Host "Installation complete. Python, pip, and FFmpeg should now be installed." -ForegroundColor Green
 

如果报错

警告: Files from a previous installation of Chocolatey were found at 'C:\ProgramData\chocolatey'. 警告: An existing Chocolatey installation was detected. Installation will not continue. This script will not overwrite existing installations. If there is no Chocolatey installation at '', delete the folder and attempt the installation again. Please use choco upgrade chocolatey to handle upgrades of Chocolatey itself. If the existing installation is not functional or a prior installation did not complete, follow these steps: - Backup the files at the path listed above so you can restore your previous installation if needed. - Remove the existing installation manually. - Rerun this installation script. - Reinstall any packages previously installed, if needed (refer to the lib folder in the backup). Once installation is completed, the backup folder is no longer needed and can be deleted.

解决办法

删除现有的 Chocolatey 安装

  1. 删除 C:\ProgramData\chocolatey 目录

    • 打开文件资源管理器,导航到 C:\ProgramData
    • 找到 chocolatey 文件夹并删除。
  2. 从环境变量中删除 Chocolatey 的路径(共有三处):

    • 右键单击“此电脑”或“计算机”,选择“属性”。
    • 选择“高级系统设置”。
    • 在“系统属性”对话框中,选择“环境变量”。
    • 在“系统变量”部分找到“Path”变量并编辑。
    • 删除路径中包含 Chocolatey 的条目。
    • 找到并删除另外两处变量名含有Chocolatey 的变量。

在代码文件Translate.py所在文件夹的路径中输入cmd

为了打包方便,创建虚拟环境,并进入

conda create whisper

conda activate whisper

使用pyinstaller打包,命令

pyinstaller --onefile --noconsole --paths "D:/ProgramData/anaconda3/envs/whisper/Lib/site-packages" --add-data "D:/ProgramData/anaconda3/envs/whisper/Lib/site-packages/tkinterdnd2;tkinterdnd2" --add-data "D:/ProgramData/anaconda3/envs/whisper/Lib/site-packages/tkinterdnd2/tkdnd/win-x64/tkdnd.tcl;tkdnd" --hidden-import=tkinterdnd2 --i 1.ico --clean Translate.py

此处感谢博主提供解决tkdnd无法打包问题的命令模板。可将模板告诉GPT,再用everything找到本地tkinterdnd2所在路径并告诉GPT,让它参考模板,但是用我提供的路径生成命令https://blog.youkuaiyun.com/qq_43079386/article/details/139725149

设置icon使用参数--i name.ico如--i cat.ico。 icon大小不得超过256*256px,可以使用photopee编辑。https://jingyan.baidu.com/article/fedf0737978d8835ad897770.html

到此,代码本体、依赖库打包完毕,系统级依赖自动安装脚本准备完毕。

接下来尝试用安装器封装一下,安装器要实现自动运行系统级依赖自动安装脚本install_dependencies.ps1,给将打包好的Translate.exe增加右键菜单和任务栏快捷方式

使用Inno Setup制作程序安装包-优快云博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值