Installation¶
For detailed guide for settings up Python on Windows, see: Windows Python Setup Guide or Environment Setup for Windows with VS Code
Requirements
Python version 3.9 (64bit) – See the associated install documents: Windows and Linux . Note that other versions of Python will not work.
M-Star CFD version 3.5+
Python Module Install
The M-Star python pre-processing module comes with the M-Star package on both Windows and Linux. On windows the mstar.pyd
module is located directly in the install directory. On Linux, the mstar python module will be named differently, mstar.cpython-39-x86_64-linux-gnu.so
. On Linux, it will be located in the lib/
sub folder of the installation. You can use any standard python module environment extension approach such as –
Use a
mstar.pth
file (Recommended) in the existing python module install path. This file should contain the absolute path to the directory with the mstar python module. Place this file in an existingLib/site-packages
sub-directory in a python virtual environment or base installation path. Example content ofmstar.pth
–C:\Program Files\M-Star CFD
Use
PYTHONPATH
environment variable. Append the full absolute path to the directory with the mstar python modulemodifying
sys.path
directly in your script prior toimport mstar
. For example,import sys sys.path.insert(0, r"C:\Program Files\M-Star CFD") import mstar
Important
For Linux Install – To use the mstar python module, you need to load the mstar.sh
environment file or override LD_LIBRARY_PATH=/path/to/mstarinstall/lib
Environment Setup for Windows with VS Code¶
Perform these installation steps¶
Install latest stable version of M-Star CFD
Install Python 3.9.13 . Choose the “Windows installer (64-bit)” option.
Install Microsoft Visual Studio Code
Open VS Code
Click View -> Extensions
Install the following extensions: Python, Python Debugger, Pylance
Create a new virtual environment¶
Create an empty project directory in a location of your choice. For this example we are placing the project at
C:\Projects\TestProject1
.Open a command prompt (cmd.exe)
Navigate to the project directory. For example
cd C:\Projects\TestProject1
Create the virtual environment:
python -m venv venv
. A new directoryc:\Projects\TestProject1\venv
will be created containg the Python environment.
Open VS Code
File - Open Folder. Select your project directory
c:\Projects\TestProject1
File - New Text File
Paste the full installation path of M-Star CFD into the file content:
C:\Program Files\M-Star CFD
File - Save As…
Navigate to
c:\Projects\TestProject1\venv\Lib\site-packages
Select
All File Types
Enter file name
mstar.pth
Click Save
Close the
mstar.pth
file tab in VS Code
At this point you have a Python virtual environment with access to the M-Star Pre API.
Testing the environment¶
To test this environment from the command line:
Open a command prompt (cmd.exe)
Navigate to the project directory. For example
cd C:\Projects\TestProject1
Activate the environment. Run the command:
venv\Scripts\activate
Start interactive python prompt:
python
Type
import mstar
in the prompt and hit enter. If you see any error, review the steps above to make sure your environment is setup correctly.Type
mstar.Initialize()
and hit enter. This will attempt to checkout an M-Star CFD pre-processor license. If you get an error, review your license setup.To exit the python session: Hit CTRL+Z. Enter.
To test this environment in VS Code:
Download an example here –
examples/simplecase2.py
. Put this script in your project directory:c:\Projects\TestProject1\test.py
.Open VS Code in the project folder. In example above,
c:\Projects\TestProject1
.Open the example script
test.py
Click View - Run. This opens the Run tab
Click
Run and Debug
.Select Python Debugger
Select Python File
A new file
simplecase.msb
should be created
Using the environment in other projects or locations¶
It is recommended to create a new Python virtual environment for each new project.
If you need to use your python environment from locations other than the project directory, you have the following options:
In a command prompt Activate the virtual environment:
c:\Projects\TestProject1\venv\Scripts\activate
. Use the environment by runningpython.exe myotherscript.py
in the command window.In VS Code. When you create a Python file, select the Python interpreter by clicking on the version number in the lower right corner of the VS Code window. Click Enter interpretter path… Then click Find… and browse to
c:\Projects\TestProject1\venv\Scripts\python.exe
.