I am attempting to leverage sympy to solve a set of equations. However, some of the equations are dependent upon functions that I can only interface via a ctypes interface. The end goal is to use fluid property calculations that are defined in the NIST Refprop python interface called ctRefprop. I have been unsuccessful in getting sympy to allow calculation of a function connected to a ctypes interface. To demonstrate the issue, I created a simple case with a very simple C++ dll that exposes two methods: The first is a function that adds two numbers together and returns their sum. The second is a subroutine that adds two numbers together and assigns the result to a third byref argument. This method is more like the ctRefprop ctypes interfaces. The simple dll works as expected when calling the methods via ctypes interface without using any sympy symbols. But when trying to use sympy symbols and an instance of the 'simple_math_class' class, I receive an error stating: 'argument 1: TypeError: Cannot convert expression to float'. Can anyone provide guidance on how I can get a ctypes interface method to work together with sympy to be able to do a numerical evaluation of an externally defined function/subroutine? I don't need the sympy process to do any symbolic manipulation of the method, I simply need to be able to do a numerical evaluation of the method using symbols that are part of a sympy set of symbols. The example code shows the simple python implementation and the C++ function code in comments. Any help is greatly appreciated. import ctypes as ct import os from sympy import symbols class simple_math_class: def __init__(self): self.load_dll_and_define_functions() def load_dll_and_define_functions(self): # Load the library self.dll = ct.cdll.LoadLibrary(os.path.join('.', 'x64', 'Debug', 'Demo_AddTwo.dll')) # Define the arguments for the function case self.dll.AddNumbers.argtypes = [ct.c_double, ct.c_double] self.dll.AddNumbers.restype = ct.c_double # Define the arguments for the byref subroutine case self.dll.AddNumbersByRef.argtypes = [ct.c_double, ct.c_double, ct.POINTER(ct.c_double)] self.dll.AddNumbersByRef.restype = None def add_numbers(self, a:float, b:float) -> float: return self.dll.AddNumbers(a, b) def add_numbers_ref(self, a:float, b:float) -> float: # Same argument type as ctRefprop result = ct.c_double(0) self.dll.AddNumbersByRef(a, b, ct.byref(result)) return result.value def add(a, b): c = simple_math_class() return c.add_numbers(a, b) def test_ctypes_sympy(): a, b = symbols('a b') result = add(a, b) print(result) if __name__ == '__main__': dll_class = simple_math_class() print('\nFunction with double return:') a = 1.0 b = 2.0 result_add_numbers = dll_class.add_numbers(a, b) print(f'\t{a} + {b} = {result_add_numbers}') print('\nSubroutine with argument byref:') c = 11.0 d = 12.0 result_add_numbers_ref = dll_class.add_numbers_ref(c, d) print(f'\t{c} + {d} = {result_add_numbers_ref}') test_ctypes_sympy() print('Done') Simple DLL Demo_AddTwo.c, MSVC build: cl /LD Demo_AddTwo.c __declspec(dllexport) double AddNumbers(double a, double b) { return a + b; } __declspec(dllexport) void AddNumbersByRef(double a, double b, double *result) { *result = a + b; } Continue reading...