简体   繁体   中英

How to get pyinstaller to include imported .py files

I have a GUI script, called ui.py, created in PySide that uses functions from another script, called DataFunctions.py. When I run the ui.py file in python it all works perfectly, and when I run the ui.exe file it will all work fine apart from the button that runs the DataFunctions.py file, which does nothing. In my ui.py file I am importing DataFunctions.py with:

import DataFunctions.py

buttonAction = DataFunctions.writeFile(filename, data)

I am using the following code to create the .exe:

pyinstaller ui.py -w -F

Am I importing the DataFunctions.py file in a way that pyinstaller doesn't support?

  1. Drop the .py extension in the import line

      import Datafunctions 
  2. Make sure the Datafunctions.py code is in the same folder.

It turns out that the DataFunctions.py file was included in the .exe, however some file paths relative to the DataFunctions.py file inside it were not set correctly due to the .exe being created in another folder. If anyone else is having similar problems, make sure you don't specify -w so that you can use the console to debug your .exe. Look here for how to find the location of the .exe file when it is run.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM