PyInstaller, boto3 and configparser
This article was first published on Python - datawookie , and kindly contributed to python-bloggers. (You can report issue about the content on this page here)
Want to share your content on python-bloggers? click here.
Want to share your content on python-bloggers? click here.
The current version of PyInstaller (6.5.0) doesn’t play nicely with the boto3
package. Here’s how to fix it.
The Problem
My requirements.txt
looks something like this:
boto3==1.20.54 botocore==1.23.54 pyinstaller==6.5.0
I wrap my script using PyInstaller.
pyinstaller -c -y --onefile crawler.py
When I build and run the executable locally it works 100% fine. However, when I build on GitHub Actions (using ubuntu-latest
) I get a flurry of error messages (most mentioning either boto3
or botocore
) that terminate with
ModuleNotFoundError: No module named 'configparser'
The Solution
The reason for the error is that PyInstaller is failing to detect the dependency on configparser
. There are two ways to address this, either on the command line:
pyinstaller -c -y --hidden-import=configparser --onefile crawler.py
or via the .spec
file:
a = Analysis( ['crawler.py'], pathex=[], binaries=[], datas=[], hiddenimports=['configparser'], hookspath=[], hooksconfig={}, runtime_hooks=[], excludes=[], noarchive=False, ) pyz = PYZ(a.pure)
To leave a comment for the author, please follow the link and comment on their blog: Python - datawookie .
Want to share your content on python-bloggers? click here.