How do I Setup PyAnsys locally and run it in Visual Studio?
How do I install the PyAnsys for Mechanical Simulation and set it up so I can work in Visual Studio?
Answers
-
I have recorded a video on this. This is Ansys INTERNAL ONLY!
2 -
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
4 -
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.
2