ansys / pydyna

Python interface to the LS-DYNA solver
https://dyna.docs.pyansys.com
MIT License
38 stars 9 forks source link

The bug in launcher.py is in the launch_grpc function, which defaults to the system’s Python path. #559

Open agvarghe opened 2 weeks ago

agvarghe commented 2 weeks ago

πŸ” Before submitting the issue

🐞 Description of the bug

While working on the on application, its observed that pydyna pre doesnt launch since it considers the python defined in the system defaults.

I observe the following error Traceback (most recent call last): File "C:\Users\agvarghe\AppData\Roaming\PYDYNA\ansys-pydyna-pre-server\kwserver.py", line 7, in import grpc ModuleNotFoundError: No module named 'grpc'

The reason is observed to be due to line https://github.com/ansys/pydyna/blob/6c05ae71c45e74f733cffa3c559efefdfebe813e/src/ansys/dyna/core/pre/launcher.py#L139C22-L139C60 here , it would be nice if we replace with subprocess.Popen(f"{sys.executable} kwserver.py", cwd=server_path, shell=True,)

πŸ“ Steps to reproduce

  1. Prepare a simple pydyna pre script
  2. Launch the script using a subprocess on a virtual env ,

πŸ’» Which operating system are you using?

Windows

πŸ“€ Which ANSYS version are you using?

2024R2

🐍 Which Python version are you using?

3.10

πŸ“¦ Installed packages

aiofiles==23.2.1 aiohappyeyeballs==2.4.0 aiohttp==3.10.5 aiomysql==0.2.0 aioshutil==1.5 aiosignal==1.3.1 aiosqlite==0.19.0 alabaster==0.7.16 altgraph==0.17.4 annotated-types==0.7.0 ansys-api-dbu==0.3.0 ansys-api-dyna==0.3.6 ansys-api-geometry==0.4.1 ansys-api-meshing-prime==0.1.2 ansys-api-platform-instancemanagement==1.1.0 ansys-bdm-api==0.1.dev15 ansys-bdm-shared-volume==0.1.dev11 ansys-dpf-core==0.12.1 ansys-dyna-core==0.4.15

thesct22 commented 2 weeks ago

This happens when launching a script using "/path/to/venv/Scripts/python script.py" which in turn launches this script using subprocess. If you activate the venv and then run the script it works fine. However, it is expected to work in both cases, so changing hard-coded "python" in scripts to using sys.executable would be preferred if the expected outcome is to use the same python for both cases.

zhangzhanqun commented 1 day ago

Hi @agvarghe, Thank you for your information, it is very helpful, now I am trying to update pydyna according to your three suggestions(issue 559,432,564), I will keep you updated on any progress.