ansys / pymapdl

Pythonic interface to MAPDL
https://mapdl.docs.pyansys.com
MIT License
424 stars 120 forks source link

PyMAPDL fails to launch, gives FileNotFoundError: [WinError 2] #2714

Closed ksraichur closed 8 months ago

ksraichur commented 8 months ago

πŸ€“ Before submitting the issue

πŸ” Description of the bug

PyMAPDL fails to launch and gives the following traceback.

FileNotFoundError                         Traceback (most recent call last)
Cell In[2], line 1
----> 1 mapdl = launch_mapdl()
      2 print(mapdl)

File D:\MyWork\Scripting\PythonVirtualEnv\venv\lib\site-packages\ansys\mapdl\core\launcher.py:1634, in launch_mapdl(exec_file, run_location, jobname, nproc, ram, mode, override, loglevel, additional_switches, start_timeout, port, cleanup_on_exit, start_instance, ip, clear_on_connect, log_apdl, remove_temp_files, remove_temp_dir_on_exit, verbose_mapdl, license_server_check, license_type, print_com, add_env_vars, replace_env_vars, version, **kwargs)
   1631         LOG.debug("Checking license server.")
   1632         lic_check.check()
-> 1634     raise exception
   1636 # Stopping license checker
   1637 if license_server_check:

File D:\MyWork\Scripting\PythonVirtualEnv\venv\lib\site-packages\ansys\mapdl\core\launcher.py:1605, in launch_mapdl(exec_file, run_location, jobname, nproc, ram, mode, override, loglevel, additional_switches, start_timeout, port, cleanup_on_exit, start_instance, ip, clear_on_connect, log_apdl, remove_temp_files, remove_temp_dir_on_exit, verbose_mapdl, license_server_check, license_type, print_com, add_env_vars, replace_env_vars, version, **kwargs)
   1597     mapdl = MapdlCorba(
   1598         loglevel=loglevel,
   1599         log_apdl=log_apdl,
   (...)
   1602         **start_parm,
   1603     )
   1604 elif mode == "grpc":
-> 1605     port, actual_run_location, process = launch_grpc(
   1606         port=port,
   1607         ip=ip,
   1608         add_env_vars=add_env_vars,
   1609         replace_env_vars=replace_env_vars,
   1610         verbose=verbose_mapdl,
   1611         **start_parm,
   1612     )
   1613     mapdl = MapdlGrpc(
   1614         ip=ip,
   1615         port=port,
   (...)
   1622         **start_parm,
   1623     )
   1624     if run_location is None:

File D:\MyWork\Scripting\PythonVirtualEnv\venv\lib\site-packages\ansys\mapdl\core\launcher.py:513, in launch_grpc(exec_file, jobname, nproc, ram, run_location, port, ip, additional_switches, override, timeout, verbose, add_env_vars, replace_env_vars, **kwargs)
    510     print(command)
    512 LOG.debug("MAPDL starting in background.")
--> 513 process = subprocess.Popen(
    514     command,
    515     shell=os.name != "nt",
    516     cwd=run_location,
    517     stdin=subprocess.DEVNULL,
    518     stdout=subprocess.PIPE,
    519     stderr=subprocess.PIPE,
    520     env=env_vars,
    521 )
    523 LOG.debug("Generating queue object for stdout")
    524 stdout_queue, _ = _create_queue_for_std(process.stdout)

File C:\Program Files\Python310\lib\subprocess.py:966, in Popen.__init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, user, group, extra_groups, encoding, errors, text, umask, pipesize)
    962         if self.text_mode:
    963             self.stderr = io.TextIOWrapper(self.stderr,
    964                     encoding=encoding, errors=errors)
--> 966     self._execute_child(args, executable, preexec_fn, close_fds,
    967                         pass_fds, cwd, env,
    968                         startupinfo, creationflags, shell,
    969                         p2cread, p2cwrite,
    970                         c2pread, c2pwrite,
    971                         errread, errwrite,
    972                         restore_signals,
    973                         gid, gids, uid, umask,
    974                         start_new_session)
    975 except:
    976     # Cleanup if the child failed starting.
    977     for f in filter(None, (self.stdin, self.stdout, self.stderr)):

File C:\Program Files\Python310\lib\subprocess.py:1435, in Popen._execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_gid, unused_gids, unused_uid, unused_umask, unused_start_new_session)
   1433 # Start the process
   1434 try:
-> 1435     hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
   1436                              # no special security
   1437                              None, None,
   1438                              int(not close_fds),
   1439                              creationflags,
   1440                              env,
   1441                              cwd,
   1442                              startupinfo)
   1443 finally:
   1444     # Child is launched. Close the parent's copy of those pipe
   1445     # handles that only the child should have open.  You need
   (...)
   1448     # pipe will not close when the child process exits and the
   1449     # ReadFile will hang.
   1450     self._close_pipe_fds(p2cread, p2cwrite,
   1451                          c2pread, c2pwrite,
   1452                          errread, errwrite)

FileNotFoundError: [WinError 2] The system cannot find the file specified

Click to add a cell.

πŸ•΅οΈ Steps To Reproduce

from ansys.mapdl.core import launch_mapdl
mapdl = launch_mapdl()

πŸ’» Which Operating System are you using?

Windows

🐍 Which Python version are you using?

3.10

πŸ“ PyMAPDL Report

Show the Report! ```text PyMAPDL Software and Environment Report Packages Requirements ********************* Core packages ------------- ansys.mapdl.core : 0.67.0 numpy : 1.26.3 platformdirs : 4.1.0 scipy : 1.12.0 grpc : Package not found ansys.api.mapdl.v0 : Package not found ansys.mapdl.reader : 0.53.0 google.protobuf : Package not found Optional packages ----------------- matplotlib : 3.8.2 pyvista : 0.43.2 pyiges : 0.3.1 tqdm : 4.66.1 Ansys Installation ****************** Version Location ------------------ 222 C:\Program Files\ANSYS Inc\v222 232 C:\Program Files\ANSYS Inc\v232 241 C:\Program Files\ANSYS Inc\v241 Ansys Environment Variables *************************** ANSYS211_PRODUCT_NO mech_2 ANSYS222_DIR C:\Program Files\ANSYS Inc\v222\ANSYS ANSYS232_DIR C:\Program Files\ANSYS Inc\v232\ANSYS ANSYS241_DIR C:\Program Files\ANSYS Inc\v241\ANSYS ANSYSCLOUDCLI_ROOT C:\Program Files\ANSYS Inc\ANSYS Cloud\ANSYS Cloud CLI\ ANSYSELECTRON_ROOT C:\Program Files\ANSYS Inc\ANSYS Cloud\ANSYS Electron\ ANSYSEM_ROOT232 C:\Program Files\AnsysEM\v232\Win64 ANSYSEM_ROOT241 C:\Program Files\AnsysEM\v241\Win64 ANSYSGPU_OVERRIDE 1 ANSYSLIC_DIR C:\Program Files\ANSYS Inc\Shared Files\Licensing ANSYSLI_ELASTIC 1 ANSYSLI_LCP 1 ANSYSLI_TIMEOUT_TCP 300 ANSYS_ELASTIC_PROJECT Test_Project ANSYS_SYSDIR winx64 ANSYS_SYSDIR32 win32 AWP_LOCALE222 en-us AWP_LOCALE232 en-us AWP_LOCALE241 en-us AWP_ROOT222 C:\Program Files\ANSYS Inc\v222 AWP_ROOT232 C:\Program Files\ANSYS Inc\v232 AWP_ROOT241 C:\Program Files\ANSYS Inc\v241 CADOE_LIBDIR222 C:\Program Files\ANSYS Inc\v222\CommonFiles\Language\en-us CADOE_LIBDIR232 C:\Program Files\ANSYS Inc\v232\CommonFiles\Language\en-us CADOE_LIBDIR241 C:\Program Files\ANSYS Inc\v241\CommonFiles\Language\en-us ```

πŸ“ Installed packages

Show the installed packages! ```text ansys-api-mapdl==0.5.1 ansys-api-platform-instancemanagement==1.0.0 ansys-mapdl-core==0.67.0 ansys-mapdl-reader==0.53.0 ansys-math-core==0.1.3 ansys-platform-instancemanagement==1.1.2 ansys-tools-path==0.4.1 anyio==4.2.0 appdirs==1.4.4 argon2-cffi==23.1.0 argon2-cffi-bindings==21.2.0 arrow==1.3.0 asttokens==2.4.1 async-lru==2.0.4 attrs==23.2.0 Babel==2.14.0 beautifulsoup4==4.12.3 bleach==6.1.0 certifi==2023.11.17 cffi==1.16.0 charset-normalizer==3.3.2 click==8.1.7 colorama==0.4.6 comm==0.2.1 contourpy==1.2.0 cycler==0.12.1 debugpy==1.8.0 decorator==5.1.1 defusedxml==0.7.1 exceptiongroup==1.2.0 executing==2.0.1 fastjsonschema==2.19.1 fonttools==4.47.2 fqdn==1.5.1 geomdl==5.3.1 grpcio==1.60.0 idna==3.6 importlib-metadata==7.0.1 ipykernel==6.29.0 ipython==8.20.0 isoduration==20.11.0 jedi==0.19.1 Jinja2==3.1.3 json5==0.9.14 jsonpointer==2.4 jsonschema==4.21.1 jsonschema-specifications==2023.12.1 jupyter-events==0.9.0 jupyter-lsp==2.2.2 jupyter_client==8.6.0 jupyter_core==5.7.1 jupyter_server==2.12.5 jupyter_server_terminals==0.5.2 jupyterlab==4.0.11 jupyterlab_pygments==0.3.0 jupyterlab_server==2.25.2 kiwisolver==1.4.5 MarkupSafe==2.1.4 matplotlib==3.8.2 matplotlib-inline==0.1.6 mistune==3.0.2 nbclient==0.9.0 nbconvert==7.14.2 nbformat==5.9.2 nest-asyncio==1.6.0 notebook_shim==0.2.3 numpy==1.26.3 overrides==7.6.0 packaging==23.2 pandocfilters==1.5.1 parso==0.8.3 pillow==10.2.0 platformdirs==4.1.0 pooch==1.8.0 prometheus-client==0.19.0 prompt-toolkit==3.0.43 protobuf==3.20.3 psutil==5.9.8 pure-eval==0.2.2 pyansys-tools-versioning==0.5.0 pycparser==2.21 Pygments==2.17.2 pyiges==0.3.1 pyparsing==3.1.1 python-dateutil==2.8.2 python-json-logger==2.0.7 pyvista==0.43.2 pywin32==306 pywinpty==2.0.12 PyYAML==6.0.1 pyzmq==25.1.2 referencing==0.32.1 requests==2.31.0 rfc3339-validator==0.1.4 rfc3986-validator==0.1.1 rpds-py==0.17.1 scipy==1.12.0 scooby==0.9.2 Send2Trash==1.8.2 six==1.16.0 sniffio==1.3.0 soupsieve==2.5 stack-data==0.6.3 terminado==0.18.0 tinycss2==1.2.1 tomli==2.0.1 tornado==6.4 tqdm==4.66.1 traitlets==5.14.1 types-python-dateutil==2.8.19.20240106 typing_extensions==4.9.0 uri-template==1.3.0 urllib3==2.1.0 vtk==9.3.0 wcwidth==0.2.13 webcolors==1.13 webencodings==0.5.1 websocket-client==1.7.0 zipp==3.17.0 ```

πŸ“ Logger output file

Show the logger output file. ```text # PASTE HERE THE CONTENT OF THE LOGGER OUTPUT FILE. ```
germa89 commented 8 months ago

Hi @ksraichur

Can you try again but logging to a file?

from ansys.mapdl.core import LOG

LOG.setLevel("DEBUG")
LOG.log_to_file("mylog.log")

from ansys.mapdl.core import launch_mapdl

mapdl = launch_mapdl(loglevel="DEBUG")

Reference: https://mapdl.docs.pyansys.com/version/dev/user_guide/troubleshoot.html#debug-in-pymapdl

Troubleshooting PyMAPDL β€” PyMAPDL
ksraichur commented 8 months ago

Thank you, @germa89. The log file is attached. mylog.log

ksraichur commented 8 months ago

Update: Launching a gRPC MAPDL session (ansys232 -grpc) and then connecting to it seems to be working fine. image

germa89 commented 8 months ago

Interesting...

Let's try to run the following.

  1. Create a directory somewhere.

  2. Open the terminal, and go inside that directory

  3. Run the following command:

    "C:\Program Files\ANSYS Inc\v231\ansys\bin\winx64\ansys231.exe" -j file -np 2  -port 50052 -grpc

    this should print something in the terminal. Copy/paste it here please.

ksraichur commented 8 months ago

@germa89 I don't have v231 on my computer. Only v222, 232, and 241. Below is the output from the above command: "The system cannot find the path specified."

germa89 commented 8 months ago

Interesting... that's the issue. From the log file you posted, it seems PyMAPDL is trying to start the 231 version, but you are right, it does not exist.

The solution would be then:

mapdl = launch_mapdl(exec_file ="C:\\Program Files\\ANSYS Inc\\v231\\ansys\\bin\\winx64\\ansys231.exe")

I wonder why MAPDL is trying to start v231.... Do you have any PYMAPDL_*** en vars?? Like PYMAPDL_MAPDL_EXEC, or PYMAPDL_MAPDL_VERSION. Can you post them here?

Ref: https://mapdl.docs.pyansys.com/version/0.67/api/_autosummary/ansys.mapdl.core.launcher.launch_mapdl.html#launch-mapdl

launch_mapdl β€” PyMAPDL
ksraichur commented 8 months ago

@germa89 - There are no environment variables starting with "py". And v232 works (see image below). image

germa89 commented 8 months ago

Perfect then. I feel curious to know why it was trying another version of PyMAPDL... Anyways, I'm closing this issue. Thank you for posting it!