How to install/use PyAnsys in Mechanical CPython console?

Options
Ayush Kumar
Ayush Kumar Member, Moderator, Employee Posts: 408
First Anniversary Ansys Employee Solution Developer Community of Practice Member First Answer
edited June 2023 in Structures

How to install/use PyAnsys in Mechanical CPython console?

Best Answer

  • Ayush Kumar
    Ayush Kumar Member, Moderator, Employee Posts: 408
    First Anniversary Ansys Employee Solution Developer Community of Practice Member First Answer
    edited May 2023 Answer ✓
    Options

    pyansys isn't installed by default in the Mechanical CPython scripting console. The user has to pip install it manually.

    Please use the following steps:

    1. Open command prompt as an administrator.
    2. Execute the command to download and install pyansys from https://pypi.org/project/pyansys/:

    "C:\Program Files\ANSYS Inc\v211\commonfiles\CPython\3_7\winx64\Release\python\python.exe" -m pip install pyansys

    1. Restart Mechanical and check if the installation is successful. enter image description here

    In case you get the following error: ValueError: numpy.ufunc size changed, may indicate binary incompatibility. Expected 216 from C header, got 192 from PyObject

    It should be resolved by upgrading the numpy version shipped with the default Ansys WB 2021R1 installation. Execute the following command in the command prompt to upgrade numpy

    "C:\Program Files\ANSYS Inc\v211\commonfiles\CPython\3_7\winx64\Release\python\python.exe" -m pip install -U numpy

Answers

  • M
    M Member, Employee Posts: 230
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
    Options

    @Ayush Kumar Can you update the link in the first line:


  • Ayush Kumar
    Ayush Kumar Member, Moderator, Employee Posts: 408
    First Anniversary Ansys Employee Solution Developer Community of Practice Member First Answer
    Options

    @M Thanks for pointing out, setting up the environment variable is not needed anymore.

  • ChrisC
    ChrisC Member Posts: 11
    First Comment
    Options

    So one can open a CPython console in Mechanical? I though it was just IronPython?

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 804
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
    Options

    @ChrisC There is actually a beta option to use CPython in Mechanical. From the WB project page go to tools / options / appearance / and turn on beta options. Then also in tools / option go to the "Mechanical" section and activate the option to use CPython in Mechanical. As this is a beta option, there is no documentation, no support on using it, and no guarantee that it will work.