MENU

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.

The current version of PyInstaller (6.5.0) doesn’t play nicely with the

boto3
boto3 package. Here’s how to fix it.

The Problem

My

requirements.txt
requirements.txt looks something like this:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
boto3==1.20.54
botocore==1.23.54
pyinstaller==6.5.0
boto3==1.20.54 botocore==1.23.54 pyinstaller==6.5.0
boto3==1.20.54
botocore==1.23.54
pyinstaller==6.5.0

I wrap my script using PyInstaller.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
pyinstaller -c -y --onefile crawler.py
pyinstaller -c -y --onefile crawler.py
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
ubuntu-latest) I get a flurry of error messages (most mentioning either
boto3
boto3 or
botocore
botocore) that terminate with

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
ModuleNotFoundError: No module named 'configparser'
ModuleNotFoundError: No module named 'configparser'
ModuleNotFoundError: No module named 'configparser'

The Solution

The reason for the error is that PyInstaller is failing to detect the dependency on

configparser
configparser. There are two ways to address this, either on the command line:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
pyinstaller -c -y --hidden-import=configparser --onefile crawler.py
pyinstaller -c -y --hidden-import=configparser --onefile crawler.py
pyinstaller -c -y --hidden-import=configparser --onefile crawler.py

or via the

.spec
.spec file:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
a = Analysis(
['crawler.py'],
pathex=[],
binaries=[],
datas=[],
hiddenimports=['configparser'],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
noarchive=False,
)
pyz = PYZ(a.pure)
a = Analysis( ['crawler.py'], pathex=[], binaries=[], datas=[], hiddenimports=['configparser'], hookspath=[], hooksconfig={}, runtime_hooks=[], excludes=[], noarchive=False, ) pyz = PYZ(a.pure)
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.