How do I Setup PyAnsys locally and run it in Visual Studio?

Ayush Kumar
Ayush Kumar Member, Moderator, Employee Posts: 389
First Anniversary Ansys Employee Solution Developer Community of Practice Member First Answer
edited December 2022 in General Language Questions

How do I install the PyAnsys for Mechanical Simulation and set it up so I can work in Visual Studio?

Tagged:

Answers

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

    I have recorded a video on this. This is Ansys INTERNAL ONLY!

    Click here for the recording

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

    UPDATE: The repository names have changed after the video was made.

    Please use the following names while pip installing the repos.

    pip install ansys-mapdl-core
    pip install ansys-dpf-core
    pip install ansys-dpf-post
    
  • Doug Addy
    Doug Addy Member, Employee Posts: 21
    First Anniversary Name Dropper First Answer Ansys Employee
    Answer ✓

    To install and configure pyAnsys to work within visual studio you need to check you have the python workflow pack installed. Run the "Visual Studio Installer" tool and click "Modify" on your installation.

    This may look different in other versions of Visual Studio (I use 2019).

    You should now be able to open and edit python projects within Visual Studio, at this point we can configure the environment to run. I would strongly suggest using a virtual environment for any python development, it will help to minimise dependency issues (as Ayush mentions in his video above).

    Option 1: Setup within Visual Studio

    With a python project opened, click the dropdown next to the debug button and select "Add Environment...".

    Give the environment a sensible name (convention is "venv" or "env") and select the base interpreter. If you have a project with a requirements.txt file then you can install dependencies from that, otherwise check the "View in Python Environments window".

    The Python Environments window will open, click on the environment you created and click "Open in Powershell".

    Option 2: Configure in terminal

    Open powershell in your project directory (you can shift + right-click to "Open powershell window here")

    Create a virtual environment and activate it:

    python -m venv ./venv
    ./venv/Scripts/activate
    

    Install pyAnsys

    Currently there are three packages that make up the pyAnsys suite, run

    pip install ansys-mapdl-core
    pip install ansys-dpf-core
    pip install ansys-dpf-post
    

    At this point you can now import and use pyansys as in the documentation.