e2nIEE / pandapipes

A pipeflow calculation tool that complements pandapower in the simulation of multi energy grids
https://www.pandapipes.org
Other
139 stars 60 forks source link

Issues Packaging PyQt5 Application with pandapipes Using PyInstaller #611

Closed JonasPfeiffer123 closed 4 months ago

JonasPfeiffer123 commented 4 months ago

Hello,

I've developed a small PyQt5 application that employs pandapipes for a simple heating network simulation. The app runs smoothly in a VS Code environment. However, I'm encountering challenges while attempting to package the app with PyInstaller: both pandapipes and pandapower are not included in the output directory, even after specifying them as --hidden-imports.

Here's what I've tried:

Using the --hidden-import flag for pandapipes and pandapower.
Creating custom hooks for pandapipes.
Ensuring all dependencies are correctly installed and paths are included.

I also attempted to build a minimal example with a script which just imports pandapipes and pandapower, but the problem still appears.

The issue seems to arise during the PyInstaller build process, not while running the code directly in VS Code. Is there anyone here who has successfully packaged an application with pandapipes using PyInstaller? Any insights or suggestions would be greatly appreciated.

Thank you!

dlohmeier commented 4 months ago

Hello @JonasPfeiffer123 , thank you for trying out new ways with pandapipes. Unfortunately, I would assume that none of the pandapipes developers has ever tried to package pandapipes (probably not even a different module) with pyinstaller. If you could narrow down your problem onto some specific parts of pandapipes (the setup file, maybe some missing specs or configs), we should be able to find a solution by adding files or specifications. Kind regards!

JonasPfeiffer123 commented 4 months ago

Hello @dlohmeier , I further analyzed my problem and I think I found the reason as well as the solution. PyInstaller seems to miss the folders which only include non-Python-Files (in my case pandapipes/std_types/library and the subfolders of pandapipes/properties so far) I had to include them as additional data.

For those who might encounter a similar issue, here's what I did: pyinstaller --add-data "C:\path\to\python\Lib\site-packages\pandapipes\std_types\library;./pandapipes/std_types/library" --add-data "C:\path\to\python\Lib\site-packages\pandapipes\properties;./pandapipes/properties" your_script.py

This ensures that the CSV files are included in the bundled application. I've found the PyInstaller documentation on adding data files particularly helpful.

This issue was not related to module import errors but rather to the missing CSV data files that were expected at runtime. Hopefully, this insight might save time for someone who is new to PyInstaller, just as I was.

As of now I can say that packaging pandapipes with PyInstaller works and my net calculation & timeseries simulation seems to be running as smoothly as in the Python-environment.

dlohmeier commented 4 months ago

Hi @JonasPfeiffer123 , thanks a lot for the feedback! Data files have already given us quite some headache before, but I guess it is individual how packaging should handle these types of files.