ansys / pydpf-core

Data Processing Framework - Python Core
http://dpf.docs.pyansys.com/
MIT License
67 stars 25 forks source link

Distribute PyDPF code through an Executable | Connection to DPF Server Issues #1382

Open gtzortzo opened 8 months ago

gtzortzo commented 8 months ago

Before submitting the issue

Description of the bug

A simple python script which starts a local dpf server works smoothly in a Python IDE. However, when an executable is created out of this script using the pyinstaller package for instance, the following error appears:

Traceback (most recent call last):
  File "pyvista\core\_vtk_core.py", line 17, in <module>
ImportError: Failed to load vtkFiltersCore: No module named vtkmodules.vtkCommonMisc

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "connect2server.py", line 2, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module
  File "ansys\dpf\core\__init__.py", line 106, in <module>
  File "ansys\dpf\core\settings.py", line 37, in set_default_pyvista_config
  File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module
  File "pyvista\__init__.py", line 9, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module
  File "pyvista\core\__init__.py", line 4, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module
  File "pyvista\core\_vtk_core.py", line 19, in <module>
ImportError: Failed to load vtkFiltersExtraction: No module named vtkmodules.vtkFiltersGeneral
[29820] Failed to execute script 'connect2server' due to unhandled exception!

When I exclude ansys.dpf.core package from the bundled executable, I get this error:

Traceback (most recent call last):
  File "connect2server.py", line 2, in <module>
ModuleNotFoundError: No module named 'ansys.dpf.core'
[31596] Failed to execute script 'connect2server' due to unhandled exception!

What I'm doing wrong? The end goal of the user is to create an executable to distribute to 3rd parties which would be able to launch PyDPF from its local PyDPF installation (not the one bundled in the executable). Is there a way to achieve this?

Thank you, George

Steps To Reproduce

1st error:

2nd error:

connect2server.txt

Which Operating System causes the issue?

Windows

Which DPF/Ansys version are you using?

Ansys 2023 R2

Which Python version causes the issue?

3.11

Installed packages

Package Version


ansys-dpf-core 0.10.1 cachetools 5.3.2 certifi 2023.11.17 charset-normalizer 3.3.2 colorama 0.4.6 contourpy 1.2.0 cycler 0.12.1 fonttools 4.47.2 google-api-core 2.15.0 google-api-python-client 2.115.0 google-auth 2.27.0 google-auth-httplib2 0.2.0 googleapis-common-protos 1.62.0 grpcio 1.60.0 httplib2 0.22.0 idna 3.6 imageio 2.28.0 imageio-ffmpeg 0.4.9 importlib-metadata 7.0.1 kiwisolver 1.4.5 matplotlib 3.8.2 numpy 1.26.3 packaging 23.2 pillow 10.2.0 pip 22.3.1 platformdirs 4.1.0 pooch 1.8.0 protobuf 4.25.2 psutil 5.9.8 pyasn1 0.5.1 pyasn1-modules 0.3.0 pyparsing 3.1.1 python-dateutil 2.8.2 pyvista 0.43.2 requests 2.31.0 rsa 4.9 scooby 0.9.2 setuptools 65.5.0 six 1.16.0 tqdm 4.66.1 uritemplate 4.1.1 urllib3 2.1.0 vtk 9.3.0 zipp 3.17.0

PProfizi commented 7 months ago

Hi @gtzortzo, Could you please share your connect2server.spec file? Also it seems that pyinstaller is not in the list of installed packages you provided for your environment. Are you sure it is the right environment?

PProfizi commented 7 months ago

Hi @gtzortzo, Writing here the conclusion for this issue following our call:

Conclusion: To build an executable with pyinstaller for pydpf-core, one needs to use a .spec file and modify it as explained above to include the gatebin binaries. I'll raise a documentation issue to document the fix, but I'll also look into making pyinstaller discover the binaries automatically.