Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyInstaller does not include imports

I am having a problem with PyInstaller including any imported custom modules. I have a main.py that calls a method

from Printer.function import Repeat

def main():
    name = input("Your Name: ")
    Repeat(3,name)

    input("Press enter to exit") 

main()

Through VS Code, everything is working.

However using pyInstaller, when I run the exe file it throws an error that the module 'function' is not found. I am running this command

pyinstaller.exe -p K:\HelloWorldEXE\Printer K:\HelloWorldEXE\main.py --onefile

Can any one shed some light on this? I don't know how to use hidden-imports or hooks to make it work

Thanks.

like image 357
Mohammed Nafie Avatar asked Sep 18 '25 20:09

Mohammed Nafie


1 Answers

Two possible solutions

1.

As @Legorooj mentioned try running it from the directory where the script is,e.g.

K:\HelloWorldEXE> pyinstaller main.py --onefile

2.

By default, python only searches current directory. So if you want you can also append the path a bit.

In your script, set the path to your package:

import sys
sys.path.append('C:\PathTo\project\package1')
import module1

That should fix the issue you were having.

like image 127
AzyCrw4282 Avatar answered Sep 21 '25 10:09

AzyCrw4282