AttributeError: module <myOtherModule> has no attribute xyz

47 views
Skip to first unread message

Gernot Schreider

unread,
Dec 18, 2024, 8:25:00 AM12/18/24
to PyInstaller
Pyinstaller vers. 6.11.1
from a python app, which runs from within VSCode I try to generate .exe with

pyinstaller -p C:\users\<myname>\AppData\Roaming\Python\Python311\site-packages 
                    -c
                  --onefile    .<mypythonapp.py
It creates the .exe but when I run it the exe throws this error
AttributeError: module <myOtherModule> has no attribute <xyz>

<xyz> being a function, which is defined in <myOtherModule>

I am importing another Python script in my app via
import <myOtherModule>

I suspected some problems with paths and tried various but did not succeed.
It is puzzling as it did work a few monts ago, I have no clue which changes cause now this error. I did update pyinstaller but that did not help though.

Any advice how to resolve is very welcome



Gernot Schreider

unread,
Dec 19, 2024, 11:14:04 AM12/19/24
to PyInstaller
I further tried to get around this issue and took the effort to replace in my app the import statement

import <myOtherModule>
with
from<myOtherModule> import x,y,z, ....
Again this works fine in VSCode environment. After
pyinstaller -c --onefile <myApp>
I get an .exe, which executes and terminates with the following error msg
...
ImportError: cannot import name 'xyz' from <myOtherModule> (C:\Users\myname\AppData\Local\Temp\_MEI260402\<myOtherModule>\__init__.pyc)
[PYI-24848:ERROR] Failed to execute script <myApp> due to unhandled exception

It seems that pyinstaller somehow finds myOtherModule but does not properly import
it. The temporary directory is not available after program termination so I cannot access the __init__.pyc file

The directory name _MEIxxxx tells me that this is from pyinstaller.

Can anyone shed some light on this please ?

Gernot Schreider

unread,
Dec 19, 2024, 2:54:22 PM12/19/24
to PyInstaller
ok, finally I could fix it
I do not fully understand it but once I got rid of my __init__.py files in the directories of my app as well as in the other directory of myOtherModule it worked.
I guess in order to better understand things I need to better understand the logic behind __init__.py and the import mechanism in Python itself.

Anyway I thought I post it here so it may be useful for someone else in a similar situation.

Thanks
Reply all
Reply to author
Forward
0 new messages