I can't exe a project using PyWebView with PyInstaller

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

I can't exe a project using PyWebView with PyInstaller
I tried using a database (sqlite3) with kivy
I can't manipulate iframes in a page with Selenium
Using a printer with Debian 10
I can't search with # google-map. ..
I got a Value Error when using JUMAN ++ with PyKNP
I can't send emails from Lambda in a VPC with Boto3 using a VPC endpoint for SES
I made a Line-bot using Python!
I can't install python3 with pyenv-vertualenv
I can't download images with Google_images_download
I can't install mysql-connector-python with anaconda
I made a fortune with Python.
When I run the exe file with pyinstaller, my PC crashes.
I can't use Japanese with pyperclip
I get a can't set attribute when using @property in python
I tried to make a todo application using bottle with python
I made a poker game server chat-holdem using websocket with python
Make Scrapy an exe with Pyinstaller
I made a daemon with Python
Using a webcam with Raspberry Pi
I tried using Amazon SQS with django-celery
Automatic update method with python Pyinstaller exe
I made a character counter with Python
I tried playing a ○ ✕ game using TensorFlow
I drew a heatmap with seaborn [Python]
I tried using Selenium with Headless chrome
I tried drawing a line using turtle
When I get an error with PyInstaller
Beginner: I made a launcher using dictionary
What I did with a Python array
I can't deploy with google app engine
I made a Hex map with Python
Equipped with a card function using payjp
I made a life game with Numpy
I made a stamp generator with GAN
I tried using pipenv, so a memo
I made a roguelike game with Python
I made a simple blackjack with Python
I can't install the package with pip.
I made a configuration file with Python
I can't see new files with yum
I made a WEB application with Django
I made a neuron simulator with Python
I want to exe and distribute a program that resizes images Python3 + pyinstaller
When I tried to create a project using Python on Docker with PyCharm, it didn't work, but it worked with Docker Compose.
I made a stamp substitute bot with line
I can't install Dask with pip on Ubuntu
I made a competitive programming glossary with Python
I made a GUI application with Python + PyQt5
I made a Twitter fujoshi blocker with Python ①
[Python] I made a Youtube Downloader with Tkinter.
I tried using mecab with python2.7, ruby2.3, php7
I get a UnicodeDecodeError when running with mod_wsgi
I made a simple Bitcoin wallet with pycoin
I made a LINE Bot with Serverless Framework!
I tried using Pythonect, a dataflow programming language.
I tried reading a CSV file using Python
Project Euler 4 Coding with a new approach fails.
[Chat De Tornado] Make a chat using WebSocket with Tornado
I played with Diamond, a metrics collection tool
I wrote a Japanese parser in Japanese using pyparsing.