Skip to content

sms tools in Windows

pyrole edited this page Jul 6, 2018 · 6 revisions

Python setup

I recommend you to install miniconda. Because you can install mathematic libraries more easily. Miniconda

(You have to choose python2.7).

Option 1: Using Mingwpy (Easy)

You need some C++ compiler to build C code inside software/models/utilFunctions_C. We are going to use gcc that comes with mingwpy (only supports Python 2.7)

Step 1: Install using pip

pip install -i https://pypi.anaconda.org/carlkl/simple mingwpy

Step 2:

Compile the files using the code below:

python compileModule.py build_ext --inplace --compiler=mingw32

That's it, if you are lucky and no issues pop up, then enjoy, otherwise go to Option 2 below.

Option 2: Using Visual ++

Prepare Visual C++ compiler

You have to prepare it to compile utilFunctions_C.

Install Windows SDK

Set up it conforming with your Windows version. Some Windows SDK cause error. Please avoid it by this way. Installing Visual Studio is also ok, but I think you don't want to do it (Because it is very heavy).

Set registry value (Visual Studio home directory)

(If you installed Visual Studio, I think you can skip this step).

The registory value of Visual Studio home is reffered by vcvars32.bat or vcvars64.bat in C:\Program Files\Microsoft Visual Studio 10.0\VC\bin(the folder name depends on your environment).

You have to set registry value as your bat file script.
For example, In my environment(x86), the script of vcvars32.bat is like below(at line 77).

:GetVSCommonToolsDirHelper32
@for /F "tokens=1,2*" %%i in ('reg query "%1\SOFTWARE\Microsoft\VisualStudio\SxS\VS7" /v "10.0"') DO (
	@if "%%i"=="10.0" (
		@SET "VS100COMNTOOLS=%%k"
	)
)
@if "%VS100COMNTOOLS%"=="" exit /B 1
@SET "VS100COMNTOOLS=%VS100COMNTOOLS%Common7\Tools\"
@exit /B 0

So I created HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\SxS\VS7 and add string 10.0 its value is C:\Program Files\Microsoft Visual Studio 10.0.

Modify VCVarsQueryRegistry.bat

VCVarsQueryRegistry.bat is in (Visual Studio Home)\Common7\Tools. This script needs Microsoft SDKs installed directory. It is set at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\xx. xx is SDK version number that you installed (I was v7.1).

You have to modify VCVarsQueryRegistry.bat as your installed version.
For example, I changed v7.0A to v7.1.

:GetWindowsSdkDirHelper
@for /F "tokens=1,2*" %%i in ('reg query "%1\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A" /v "InstallationFolder"') DO (
	@if "%%i"=="InstallationFolder" (
		@SET "WindowsSdkDir=%%k"
	)
)
@if "%WindowsSdkDir%"=="" exit /B 1
@exit /B 0

Run compile script

Your SDK is newer than based one, so execute set VS90COMNTOOLS=%VSXXXCOMNTOOLS% before(XXX is your version).
For example, I execute set VS90COMNTOOLS=%VS100COMNTOOLS%.

And remove libraries=['m'], from compileModule.py. This option is for gcc, so we don't need it.

Then, run compile. python compileModule.py build_ext --inplace (at How to use).

I think you will success to compile.

Create environment for sms-tools

Use conda command to create environment.

conda create -n sms-tools-env ipython numpy matplotlib scipy cython pip

Install pygame

pygame can not install from conda. so you have to install it by pip. You can download whl file from below site.

Unofficial Windows Binaries for Python Extension Packages

Activate your environment and install the whl file.

activate sms-tools-env
pip install pygame‑xxxx.whl

Activate and run script

The setup is end! You can run script.

cd software/models_interface
activate sms-tools-env
python models_GUI.py