Issue with Python Integration of Vensim Model (Reinstall Vensim Error 977)
Posted: Fri Sep 20, 2024 10:28 am
I am encountering difficulties integrating my Vensim DSS model with Python. However, when attempting to load the Python model through Visual Studio, I receive a "Reinstall Vensim" prompt. I have reinstalled and updated Vensim, Python, and Visual Studio (using "Run as Administrator") three times, but the issue persists. Additionally, there are no other users on my PC, and I am using my account with administrator privileges.
Could you please assist me with this issue? If you have any suggestions or additional instructions to resolve this problem, I would greatly appreciate it. You can see all of my specifications below.
Windows Specification:
Edition Windows 10 Pro
Version 22H2
Installed on 27.11.2020
OS build 19045.3324
Experience Windows Feature Experience Pack 1000.19041.1000.0
About Vensim:
DSS 10.2.1
The Code:
import ctypes
import os
# Step 1: Load the Vensim DLL using ctypes
vensim_dll_path = r'C:\Program Files (x86)\Vensim\vendll64.dll'
vensim = ctypes.windll.LoadLibrary(vensim_dll_path)
if vensim:
print("Vensim DLL loaded successfully.")
else:
raise Exception("Failed to load Vensim DLL.")
# Define Vensim function prototypes
vensim_command = vensim.vensim_command
vensim_command.argtypes = [ctypes.c_char_p]
vensim_command.restype = ctypes.c_int
# Step 2: Load the Vensim model
def load_vensim_model(model_path):
model_path_bytes = model_path.encode('utf-8')
load_status = vensim_command(f"SPECIAL>LOADMODEL|{model_path}".encode('utf-8'))
if load_status == 1:
print("Model loaded successfully!")
else:
print(f"Failed to load the model. Check if the model path is correct or if the model is in the correct format.")
print(f"Load status: {load_status}")
return load_status
# Use the published model (.vpm or .vpmx)
model_path = r'C:\Users\....\Desktop\DEMOfinal.vpmx'
# Check if the model exists and then attempt to load it
if os.path.exists(model_path):
print(f"Model found at: {model_path}")
load_vensim_model(model_path)
else:
print(f"Model not found at: {model_path}")
Could you please assist me with this issue? If you have any suggestions or additional instructions to resolve this problem, I would greatly appreciate it. You can see all of my specifications below.
Windows Specification:
Edition Windows 10 Pro
Version 22H2
Installed on 27.11.2020
OS build 19045.3324
Experience Windows Feature Experience Pack 1000.19041.1000.0
About Vensim:
DSS 10.2.1
The Code:
import ctypes
import os
# Step 1: Load the Vensim DLL using ctypes
vensim_dll_path = r'C:\Program Files (x86)\Vensim\vendll64.dll'
vensim = ctypes.windll.LoadLibrary(vensim_dll_path)
if vensim:
print("Vensim DLL loaded successfully.")
else:
raise Exception("Failed to load Vensim DLL.")
# Define Vensim function prototypes
vensim_command = vensim.vensim_command
vensim_command.argtypes = [ctypes.c_char_p]
vensim_command.restype = ctypes.c_int
# Step 2: Load the Vensim model
def load_vensim_model(model_path):
model_path_bytes = model_path.encode('utf-8')
load_status = vensim_command(f"SPECIAL>LOADMODEL|{model_path}".encode('utf-8'))
if load_status == 1:
print("Model loaded successfully!")
else:
print(f"Failed to load the model. Check if the model path is correct or if the model is in the correct format.")
print(f"Load status: {load_status}")
return load_status
# Use the published model (.vpm or .vpmx)
model_path = r'C:\Users\....\Desktop\DEMOfinal.vpmx'
# Check if the model exists and then attempt to load it
if os.path.exists(model_path):
print(f"Model found at: {model_path}")
load_vensim_model(model_path)
else:
print(f"Model not found at: {model_path}")