Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
3 tasks done
gtzortzo opened this issue Jan 26, 2024 · 2 comments
Open
3 tasks done
Assignees
Labels
bug Something isn't working

Comments

@gtzortzo
Copy link

gtzortzo commented Jan 26, 2024

Before submitting the issue

  • I have checked for Compatibility issues
  • I have searched among the existing issues
  • I am using a Python virtual environment

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:

  • Go to the directory of the connect2server.py file
  • Launch CMD
  • Run this command: pyinstaller --onefile connect2server.py
  • Go to the created dist directiory and launch CMD
  • Run this command: connect2server.exe
  • The 1st error in the above description will appear

2nd error:

  • Go to the directory of the connect2server.py file
  • Launch CMD
  • Run this command: pyinstaller --onefile --exclude-module ansys.dpf.core connect2server.py
  • Go to the created dist directiory and launch CMD
  • Run this command: connect2server.exe
  • The 2nd error in the above description will appear

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

@gtzortzo gtzortzo added the bug Something isn't working label Jan 26, 2024
@PProfizi
Copy link
Contributor

PProfizi commented Feb 19, 2024

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
Copy link
Contributor

PProfizi commented Feb 20, 2024

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

  • The first issue linked to vtk was due to the fact that somehow when running pyinstaller it did not pick up the current Python venv. This was solved by running pip install pyinstaller in the current venv.
  • Then, the issue was that pyinstaller was not including the ansys/dpf/gatebin binaries in the executable, resulting in runtime errors for your script. This was solved by modifying the .spec file used when running pyinstaller connect2server.spec, specifically the Analysis object declaration, to include arguments hidden_imports=['ansys/dpf/gatebin'] and binaries=[(r'path_to_gatebin_DPFCLient_API.dll', 'ansys/dpf/gatebin'), (r'path_to_gatebin_Ans.Dpf.GrpcCLient.dll', 'ansys/dpf/gatebin')]. This is required due to ansys-dpf-gatebin being now included in ansys-dpf-core but pyinstaller is not picking it up.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants