Windows Python Setup Guide

This guide will walk you through the steps necessary to setup the recommended Python and M-Star Pre API environment. We will install the following software –

  • Python 3.9.13

  • Visual Studio Code

  • Visual Studio Code Python Extension

Prerequisites

  • M-Star CFD installed – See Windows

  • M-Star CFD license is setup – See Licensing . We recommend that you setup your license using an environment variable. Set mstar_LICENSE to your license server, eg. 5053@license-server, or the path to the directory containing your license file, eg. c:\licenses.

Before you start

  • Take note of the existing M-Star CFD install location, eg. C:\Program Files\M-Star CFD

Install Python

We are using the 3.9 line of Python distributed by python.org. On Windows, M-Star currently only supports Python 3.9.

Download and run - https://www.python.org/ftp/python/3.9.13/python-3.9.13-amd64.exe

Customize installation

Optional Features (leave default) – Next

Advanced Options – Enable Install for all users. Leave rest as default. Note the install location. Click Install

Install Visual Studio Code

VS Code is the recommended Python file editor on Windows, however you may use whatever text editor you like. Whatever editor you use, just be aware of which Python installation is being invoked, since many computers will have multiple Python installations and environments.

Download and install https://code.visualstudio.com/

Open VS Code

On the left, click the Extensions tab

Type “python” in the search

Click the first “Python” result

Click “Install”

VS Code should now have the Python extension installed

Verify PYTHONPATH is not set

Verify no other programs have set the PYTHONPATH environment variable. This can cause our new python environment to fail. It can also cause issues running M-Star Post.

Click start button, type “Settings”, open the Settings app.

In the search tool, enter “environment”. Click “Edit the system environment variables”

In the System Properties window, click Environment Variables… button

Search the user and system variables for PYTHONPATH. If one is found, Delete the variable and restart the computer. Note that this may cause other python environments to break.

Create pth file

This is a text file containing the full absolute path to your M-Star CFD install location. This allows your python interpreter to find the mstar module at runtime.

Open Notepad

Paste the location of the M-Star CFD installation in this file. By default on windows this is

C:\Program Files\M-Star CFD

File - Save As

Change Save as type: All Files

Save the file as mstar.pth . Note the location where you saved this file. We will be copying this file to another location later on.

Setup M-Star Python environment

Choose one of the below options when setting up your environment.

Global Install Option

This option will install the M-Star python module into your global Python installation. The advantage of this approach is its simplicity but has the drawback of being less flexible and prone to issues later on if another program changes your installation or environment. Whenever possible, prefer virtual environments.

In Windows File Explorer:

Navigate to your Python installation, eg. C:\Program Files\Python 3.9.13

Go to the sub-directory Lib\site-packages.

Copy the previously created mstar.pth file into this Lib\site-packages directory.

Troubleshooting

Can I specify my license inside my script?

Yes, use the os.environ to set the mstar_LICENSE variable. For example:

import os
os.environ['mstar_LICENSE] = '5053@licenseserver'
I am not able to load the mstar module, can I try something else?

Yes, set the path to the M-Star installation at runtime. For example:

import sys
sys.path.insert(0, r'c:\path\to\M-star CFD')
import mstar