ansys / pymechanical

Pythonic interface to Ansys Mechanical ™
https://mechanical.docs.pyansys.com/
MIT License
36 stars 18 forks source link

Encountour DLL error when init instance app=mech.App(version=232) #699

Closed zueskalare closed 5 months ago

zueskalare commented 5 months ago

Discussed in https://github.com/ansys/pymechanical/discussions/698

Originally posted by **zueskalare** April 11, 2024 # Enviroument - Using linux HPC - Ansys version 232 - python version 3.11.0 (clean env and just run pip install pyansys) # Error **DllNotFoundException**: Ans.Common.WBLogger.dll assembly: type: member:(null) at (wrapper managed-to-native) Ansys.Common.WB1ManagedUtils.Logger+Imports.wb_logger_log_message(int,string,string) at Ansys.Common.WB1ManagedUtils.Logger.LogMessage (Ansys.Common.WB1ManagedUtils.Logger+LoggerSeverity severity, System.String context, System.String message) [0x00000] in :0 at Ansys.Mechanical.Embedding.Application.trace (System.String msg) [0x00000] in <453e70f297334f5db0d8841fbf1f0dac>:0 at Ansys.Mechanical.Embedding.Application.startApp (System.String dbFile) [0x00000] in <453e70f297334f5db0d8841fbf1f0dac>:0 at Ansys.Mechanical.Embedding.Application..ctor (System.String dbFile) [0x00006] in <453e70f297334f5db0d8841fbf1f0dac>:0 at (wrapper managed-to-native) System.Reflection.RuntimeConstructorInfo.InternalInvoke(System.Reflection.RuntimeConstructorInfo,object,object[],System.Exception&) at System.Reflection.RuntimeConstructorInfo.InternalInvoke (System.Object obj, System.Object[] parameters, System.Boolean wrapExceptions) [0x00005] in :0 # Question: I thought the problem should be on windows platform. Is there any platform compatability problem?
dipinknair commented 5 months ago

@zueskalare Could you please give more information?

zueskalare commented 5 months ago

@zueskalare Could you please give more information?

  • Were you using pymechanical remote or embedding?
  • What is the Linux distribution?
  • Can you provide where exactly are you getting this error ?

I was using jupyter, and choose the a clean env and install only matplotlib & pyansys using pip install -U here is the code

import os
import ansys.mechanical.core as mech
from ansys.mechanical.core import launch_mechanical
from ansys.mechanical.core.examples import delete_downloads, download_file
from matplotlib import image as mpimg
from matplotlib import pyplot as plt
from ansys.mechanical.core import App
os.environ['AWP_ROOT232'] = '/apps/ANSYS/ansys_inc/v232'
app = mech.App(version=232) # here happens the error

Here is all the error

{
    "name": "DllNotFoundException",
    "message": "Ans.Common.WBLogger.dll assembly:<unknown assembly> type:<unknown type> member:(null)
  at (wrapper managed-to-native) Ansys.Common.WB1ManagedUtils.Logger+Imports.wb_logger_log_message(int,string,string)
  at Ansys.Common.WB1ManagedUtils.Logger.LogMessage (Ansys.Common.WB1ManagedUtils.Logger+LoggerSeverity severity, System.String context, System.String message) [0x00000] in <eff273037c1b4021aa0bb7b554088b82>:0 
  at Ansys.Mechanical.Embedding.Application.trace (System.String msg) [0x00000] in <453e70f297334f5db0d8841fbf1f0dac>:0 
  at Ansys.Mechanical.Embedding.Application.startApp (System.String dbFile) [0x00000] in <453e70f297334f5db0d8841fbf1f0dac>:0 
  at Ansys.Mechanical.Embedding.Application..ctor (System.String dbFile) [0x00006] in <453e70f297334f5db0d8841fbf1f0dac>:0 
  at (wrapper managed-to-native) System.Reflection.RuntimeConstructorInfo.InternalInvoke(System.Reflection.RuntimeConstructorInfo,object,object[],System.Exception&)
  at System.Reflection.RuntimeConstructorInfo.InternalInvoke (System.Object obj, System.Object[] parameters, System.Boolean wrapExceptions) [0x00005] in <e85874d36dd54c51a7dcd93d72f2c404>:0 ",
    "stack": "---------------------------------------------------------------------------
DllNotFoundException                      Traceback (most recent call last)
Cell In[3], line 1
----> 1 app = mech.App(version=232)
      2 globals().update(mech.global_variables(app, True))
      3 print(app)

File ~/.conda/envs/ansys/lib/python3.10/site-packages/ansys/mechanical/core/embedding/app.py:128, in App.__init__(self, db_file, private_appdata, **kwargs)
    125     profile.update_environment(os.environ)
    126     atexit.register(_cleanup_private_appdata, profile)
--> 128 self._app = _start_application(configuration, self._version, db_file)
    129 runtime.initialize(self._version)
    130 connect_warnings(self)

File ~/.conda/envs/ansys/lib/python3.10/site-packages/ansys/mechanical/core/embedding/app.py:67, in _start_application(configuration, version, db_file)
     65     return Ansys.Mechanical.Embedding.Application(db_file, addin_configuration_name)
     66 else:
---> 67     return Ansys.Mechanical.Embedding.Application(db_file)

DllNotFoundException: Ans.Common.WBLogger.dll assembly:<unknown assembly> type:<unknown type> member:(null)
  at (wrapper managed-to-native) Ansys.Common.WB1ManagedUtils.Logger+Imports.wb_logger_log_message(int,string,string)
  at Ansys.Common.WB1ManagedUtils.Logger.LogMessage (Ansys.Common.WB1ManagedUtils.Logger+LoggerSeverity severity, System.String context, System.String message) [0x00000] in <eff273037c1b4021aa0bb7b554088b82>:0 
  at Ansys.Mechanical.Embedding.Application.trace (System.String msg) [0x00000] in <453e70f297334f5db0d8841fbf1f0dac>:0 
  at Ansys.Mechanical.Embedding.Application.startApp (System.String dbFile) [0x00000] in <453e70f297334f5db0d8841fbf1f0dac>:0 
  at Ansys.Mechanical.Embedding.Application..ctor (System.String dbFile) [0x00006] in <453e70f297334f5db0d8841fbf1f0dac>:0 
  at (wrapper managed-to-native) System.Reflection.RuntimeConstructorInfo.InternalInvoke(System.Reflection.RuntimeConstructorInfo,object,object[],System.Exception&)
  at System.Reflection.RuntimeConstructorInfo.InternalInvoke (System.Object obj, System.Object[] parameters, System.Boolean wrapExceptions) [0x00005] in <e85874d36dd54c51a7dcd93d72f2c404>:0 "
}

**the linux distribution : It's a machine instance by submitting a slurm job

uname -a
>>> Linux a2-4 4.18.0-477.15.1.el8_8.x86_64 #1 SMP Wed Jun 28 15:04:18 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
dipinknair commented 5 months ago

@zueskalare mechanical-env has to be called before we start python. Jupyter notebook starts python kernel using kernel.json

{ "argv": [ "python", "-m", "ipykernel_launcher", "-f", "{connection_file}" ], "display_name": "Python 3 (ipykernel)", "language": "python", "metadata": { "debugger": true } }

which needs to be modified if you have to work pymechanical embedding with jupyter in Linux.

steps :

  1. activate venv and install pymechanical (pip install ansys-mechanical-core)
  2. List the kernel ( jupyter kernelspec list) python3 /user/username/pymechanical/.venv/share/jupyter/kernels/python3 (this directory is just an example)
  3. Edit respective kernel file in your venv and add mechanical-env in the begining
    {
    "argv": [
    "mechanical-env",
    "python",
    "-m",
    "ipykernel_launcher",
    "-f",
    "{connection_file}"
    ],
    "display_name": "Python 3 (ipykernel)",
    "language": "python",
    "metadata": {
    "debugger": true
    }
  4. Install kernel after modification jupyter kernelspec install /user/username/pymechanical/.venv/share/jupyter/kernels/python3/ --user (use respective kernel path in you venv)

Use same kernel you modified when using jupyter.

Let me know if this helps.

dipinknair commented 5 months ago

@zueskalare if this solves the issue, the please close the issue or else provide more information.

zueskalare commented 5 months ago

@dipinknair Sorry for not replying in time. I don't know wheter i set the Jupyter correctly, so i create a new cond venv and choose not to use vscode here is the history

   26  [2024-04-17 14:55:58]  conda create py_mech
   27  [2024-04-17 14:56:13]  conda create -n  py_mech python==3.11
   28  [2024-04-17 14:57:26]  conda activate py_mech
   32  [2024-04-17 14:58:49]  pip install -U  ansys-mechanical-core 
   34  [2024-04-17 14:59:12]  pip install matplotlib
   36  [2024-04-17 15:00:10]  pip install requests 
   37  [2024-04-17 15:00:14]  python topology_optimization_cantilever_beam.py 

when install packages, it have these conficts but it give error as before

requests-ntlm 1.2.0 requires cryptography>=1.3, which is not installed.
ansys-simai-core 0.1.4 requires requests_toolbelt<2,>=1.0.0, which is not installed.
ansys-dynamicreporting-core 0.5.1 requires filelock>=3.7.1, which is not installed.
ansys-dynamicreporting-core 0.5.1 requires pytz>=2021.3, which is not installed.
ansys-fluent-core 0.19.2 requires lxml>=4.9.2, which is not installed.
ansys-fluent-core 0.19.2 requires pandas>=1.1.5, which is not installed.
ansys-fluent-core 0.19.2 requires pyyaml>=6.0, which is not installed.
twine 5.0.0 requires keyring>=15.1, which is not installed.
twine 5.0.0 requires pkginfo>=1.8.1, which is not installed.
twine 5.0.0 requires requests-toolbelt!=0.9.0,>=0.8.0, which is not installed.
ansys-additive-core 0.17.2 requires pandas>=1.3.2, which is not installed.
ansys-additive-core 0.17.2 requires panel>=1.2.1, which is not installed.
ansys-geometry-core 0.4.11 requires scipy<2,>=1.7.3, which is not installed.
python-keycloak 2.0.0 requires urllib3<2.0.0,>=1.26.0, but you have urllib3 2.2.1 which is incompatible.
ansys-dynamicreporting-core 0.5.1 requires urllib3<2.0.0, but you have urllib3 2.2.1 which is incompatible.
ansys-pyensight-core 0.7.8 requires urllib3<2, but you have urllib3 2.2.1 which is incompatible.
pyansys 2024.1.7 requires ansys-mechanical-core==0.10.8, but you have ansys-mechanical-core 0.10.9 which is incompatible.

FYI: I found that there is a package pyansys-docker, but docker is not availabe on HPC, does it affect?

dipinknair commented 5 months ago

@zueskalare Sorry for delay in response. That should not be an issue. If you just want to work with pymechanical I would suggest install only pymechanical package in your venv and test. You can do following.

conda create py_mech
conda create -n  py_mech python==3.11
conda activate py_mech
pip install -U  ansys-mechanical-core 
pip install matplotlib
pip install requests 
xvfb-run mechanical-env python topology_optimization_cantilever_beam.py 

use xvfb-run if you are running in system without graphic display. mechanical-env should be used before you run the python script. Please try and let me know.

zueskalare commented 5 months ago

Thanks, xvfb-run makes it works now.