Virtual Environment venv

M Member, Employee Posts: 231
First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member

It is recommended to use a virtual environment when using pyansys codes. Those who understand why should explain it.
However, the bare bones getting a virtual environment set up for a IDE is shown below. This script assumes you have python set to path in your environmental variables and can then build a venv with a name of your choice in the C drive, update pip and then install spyder, pyansys, etc or if you change things a jupyter notbook. It installs the pyansys module which is not small, if only use one pyansys module, just change that line.

set myvenv=bob
set defaultDir="D:\\"
python -m venv "C:\%myvenv%"
"C:\%myvenv%\Scripts\python" -m pip install --upgrade pip
"C:\%myvenv%\Scripts\pip" install pyansys
"C:\%myvenv%\Scripts\pip" install spyder
REM "C:\%myvenv%\Scripts\pip" install jupyterlab
REM  "C:\%myvenv%\Scripts\jupyter.exe" lab --notebook-dir=%defaultDir%

These are commands for the DOS command prompt.
There are a 1000 ways to do this smarter, but if you set this up as a .bat and make a shortcut for your desktop, you have a quick tool to open your IDE with everything pyansys installed.
If you don't use spyder, search for a method to launch your IDE of choice (pyansys is IDE agnostic) and adapt the line that launches the exe. spyder is just another module.
A better method would be to have a requirements.txt file in the same directory and just use pip to install requirements.
When you re-use the .bat you could change the pip install commands to pip install --upgrade which will then just update the packages.
Read the pip and python documentation.