'After pyinstaller: ImportError: attempted relative import with no known parent package
in pretty new to the Python game and i am trying to convert my python tkinker GUI to an .exe via pyinstaller. The converting succeed if i comment out everything related to a specific library. I only have a problem "refrencing" that imported library called: pylibdmtx.
Here is my .spec:
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(['C:/Users/peter.xxx/PycharmProjects/WINSTORE CREATE DROPS/CREATE_DROPS.py', 'CREATE_DROPS.py'],
pathex=['C:/Users/peter.xxx/PycharmProjects/WINSTORE CREATE DROPS/venv/Lib/site-packages/pylibdmtx', 'C:\\Users\\peter.xxx\\PycharmProjects\\WINSTORE CREATE DROPS'],
binaries=[],
datas=[('C:/Users/peter.xxx/PycharmProjects/WINSTORE CREATE DROPS/img', 'img/'), ('C:/Users/peter.xxx/PycharmProjects/WINSTORE CREATE DROPS/DROP CODES', 'DROP CODES/')],
hiddenimports=['pylibdmtx'],
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='CREATE_DROPS',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='CREATE_DROPS')
... i get follwing error when i execute the .exe via cmd:
Traceback (most recent call last):
File "CREATE_DROPS.py", line 5, in <module>
File "c:\python\python38\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
exec(bytecode, module.__dict__)
File "venv\Lib\site-packages\pylibdmtx\pylibdmtx.py", line 9, in <module>
ImportError: attempted relative import with no known parent package
[26944] Failed to execute script CREATE_DROPS
...
so its basicly only missing some imported functions from other .py's ... How do i tell pyinstaller where to find?
Here are my imports in the CREATE_DROPS.py:
import tkinter as tk
from PIL import ImageTk, Image, ImageDraw, ImageFilter, ImageFont
from barcode.writer import ImageWriter
import barcode, pyodbc, tkinter.messagebox, os, time, sys
from pylibdmtx.pylibdmtx import encode
from tkinter.ttk import Treeview, Combobox
from pynput.keyboard import Key, Controller
from tkinter import ttk
import pkg_resources.py2_warn
"from pylibdmtx.pylibdmtx import encode" is the problemmaker..
and finally these are the imports in the library pylibdmtx.py from the error:
from .pylibdmtx_error import PyLibDMTXError
from .wrapper import (
c_ubyte_p, dmtxImageCreate, dmtxImageDestroy, dmtxDecodeCreate,
dmtxDecodeDestroy, dmtxRegionDestroy, dmtxMessageDestroy, dmtxTimeAdd,
dmtxTimeNow, dmtxDecodeMatrixRegion, dmtxRegionFindNext,
dmtxMatrix3VMultiplyBy, dmtxDecodeSetProp, DmtxPackOrder, DmtxProperty,
DmtxUndefined, DmtxVector2, EXTERNAL_DEPENDENCIES,
DmtxSymbolSize, DmtxScheme, dmtxEncodeSetProp, dmtxEncodeDataMatrix,
dmtxImageGetProp, dmtxEncodeCreate, dmtxEncodeDestroy
)
Solution 1:[1]
Try to removing CREATE_DROPS.py
from your .spec
file.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | innicoder |