Python pyinstaller ModuleNotFoundError even with hidden import

36 Views Asked by At

I have 2 files like this. addict is a library, installed by using pip install addict. https://pypi.org/project/addict/

# myimport.py
from addict import Dict

and

# main.py
from pyinstaller_test.myimport import *
print('Hello world')

The folder structure is:

huyduc@my-pc:~/pyinstaller_test$ ls
__init__.py  main.py  myimport.py

I run pyinstaller by using

pyinstaller --hidden-import addict --onefile --name main *.py
128 INFO: PyInstaller: 6.5.0, contrib hooks: 2024.3
128 INFO: Python: 3.8.5
136 INFO: Platform: Linux-5.8.0-50-generic-x86_64-with-glibc2.29
137 INFO: wrote /home/huyduc/pyinstaller_test/main.spec
139 INFO: Extending PYTHONPATH with paths
['/home/huyduc', '/home/huyduc', '/home/huyduc']
238 INFO: checking Analysis
239 INFO: Building because pathex changed
239 INFO: Initializing module dependency graph...
240 INFO: Caching module graph hooks...
250 INFO: Analyzing base_library.zip ...
673 INFO: Loading module hook 'hook-heapq.py' from '/home/huyduc/.local/lib/python3.8/site-packages/PyInstaller/hooks'...
815 INFO: Loading module hook 'hook-encodings.py' from '/home/huyduc/.local/lib/python3.8/site-packages/PyInstaller/hooks'...
1653 INFO: Loading module hook 'hook-pickle.py' from '/home/huyduc/.local/lib/python3.8/site-packages/PyInstaller/hooks'...
2258 INFO: Caching module dependency graph...
2343 INFO: Running Analysis Analysis-00.toc
2343 INFO: Looking for Python shared library...
2361 INFO: Using Python shared library: /usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0
2362 INFO: Analyzing /home/huyduc/pyinstaller_test/__init__.py
2363 INFO: Analyzing /home/huyduc/pyinstaller_test/main.py
2365 INFO: Analyzing /home/huyduc/pyinstaller_test/myimport.py
2365 INFO: Processing module hooks...
2375 INFO: Performing binary vs. data reclassification (2 entries)
2381 INFO: Looking for ctypes DLLs
2385 INFO: Analyzing run-time hooks ...
2392 INFO: Looking for dynamic libraries
2581 INFO: Warnings written to /home/huyduc/pyinstaller_test/build/main/warn-main.txt
2594 INFO: Graph cross-reference written to /home/huyduc/pyinstaller_test/build/main/xref-main.html
2596 INFO: checking PYZ
2617 INFO: checking PKG
2618 INFO: Building because toc changed
2618 INFO: Building PKG (CArchive) main.pkg
4640 INFO: Building PKG (CArchive) main.pkg completed successfully.
4641 INFO: Bootloader /home/huyduc/.local/lib/python3.8/site-packages/PyInstaller/bootloader/Linux-64bit-intel/run
4641 INFO: checking EXE
4641 INFO: Building because toc changed
4641 INFO: Building EXE from EXE-00.toc
4642 INFO: Copying bootloader EXE to /home/huyduc/pyinstaller_test/dist/main
4642 INFO: Appending PKG archive to custom ELF section in EXE
4710 INFO: Building EXE from EXE-00.toc completed successfully.

but if I run I will get this error

huyduc@my-pc:~/pyinstaller_test$ ./dist/main 
Traceback (most recent call last):
  File "main.py", line 1, in <module>
    from pyinstaller_test.myimport import *
  File "PyInstaller/loader/pyimod02_importers.py", line 419, in exec_module
  File "myimport.py", line 1, in <module>
    from addict import Dict
ModuleNotFoundError: No module named 'addict'
[1069094] Failed to execute script 'main' due to unhandled exception!

I'm not using any venv. What might cause this and how to fix this problem? Thank you.

0

There are 0 best solutions below