Currently (as of PyWebView 3.1), when trying to exe an application using PyWebView as it is with PyInstaller, it seems that there is a problem that compilation is interrupted with the error message Pyinstaller hook can't find WebBrowserInterop.x64.dll
. is.
Roughly as in the above issue, it seems that the webhook for PyInstaller does not point to the correct path, and an error occurs.
As I saw the above, it seems that the latest version has been corrected, but it has not been reflected in the public module yet.
So, it is troublesome to manually fix the webhook until it is fixed, so I wrote a PowerShell script.
We use a PowerShell script to compile with PyInstaller, so call the following code before using PyInstaller in the file.
if(Select-String "library = join\(sitepack, 'lib', dll_name\)" -Path .\.venv\Lib\site-packages\PyInstaller\hooks\hook-webview.py){
Write-Host "> Fix PyInstaller\hooks\hook-webview.py"
$data = Get-Content .\.venv\Lib\site-packages\PyInstaller\hooks\hook-webview.py | % {$_ -replace "library = join\(sitepack, 'lib', dll_name\)","library = join(sitepack, 'webview', 'lib', dll_name)"}
$data | Out-File .\.venv\Lib\site-packages\PyInstaller\hooks\hook-webview.py
}
However, PowerShell 5.x can't handle UTF-8 without BOM, so if you leave it as it is, you will end up with a webhook file that PyInstaller can't read properly.
Since PowerShell 6.x can be used without problems, install `pwsh (PowerShell 6.x) from Chocolatey etc. in advance and execute this script on PowerShell 6.
I'll also add some code to drop when I try to launch a script in PowerShell 5.x in case I accidentally run it in PowerShell 5.x.
if(!($PSVersionTable["PSCompatibleVersions"].Major -contains 6)){
Write-Host @'
This script must be PowerShell version 6 or higher before it will work properly.
The shell currently running is PowerShell version 5 or lower.
Use the `pwsh` command to change to PowerShell 6.
'@
exit
}
It is safe to write this on the first line. You will notice it when you get a warning.
Recommended Posts