I have any issue trying to run my executable made by PyInstaller 3.6.
My code works fine in Idle, but doesn't run when made into an executable.
I get the following error:
AttributeError: module 'importlib' has no attribute 'machinery'
This method that seems to throw the error only when using PyInstaller;
def getVariables(filename):
'''Loads variables from variables.txt'''
try:
import importlib
import types
with open(filename) as f:
loader = importlib.machinery.SourceFileLoader('data',filename)
mod = types.ModuleType(loader.name)
loader.exec_module(mod)
return mod
except:
logger.exception('Exception occured:')
Things i've done:
- Re-installed PyInstaller; also tried multiple versions
- Re-installed importlib/importlib-metadata
- Tried different version of Python (3.6.5, 3.7.7)
I make the executable using the following command;
pyinstaller --clean update.spec
update.spec:
# -*- mode: python -*-
#import win32wnet,sys
import PyInstaller.config;
PyInstaller.config.CONF['distpath'] = "./apps/App/"
PyInstaller.config.CONF['workpath'] = "Z:\\Workspace\\David\\Applications\\src\\"
block_cipher = None
a = Analysis(['Z:\\Workspace\\David\\Applications\\src\\Update.py'],
pathex=['Z:\\Workspace\\David\\Applications\\bin\\apps\\App'],
binaries=[],
datas=[],
hiddenimports=["win32process"],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
[],
exclude_binaries=True,
name='Update',
icon='Z:\\Workspace\\David\\Applications\\src\\Icons\\Icon.ico',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=False,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=False,
name='Update')
Version Info:
- Python - 3.6.5
- PyInstaller - 3.6
- importlib - 1.0.4
- importlib-metadata- 1.6.0