[Python.NET] avoiding runtime error R6034

Cameron Hayne cameron.hayne at introspect.ca
Sat Feb 21 00:21:49 CET 2015

I’ve started using the version of PythonDotNet from https://github.com/renshawbay/pythonnet
to call my Python modules from C#.
I encountered the Microsoft runtime error R6034 which
(according to <http://stackoverflow.com/questions/14552348/runtime-error-r6034-in-embedded-python-application>)
is caused by extra copies of the file "msvcr90.dll” in folders on the Windows execution PATH.
I worked around this problem by calling the following function in my initialization code.

def cleanWindowsPathOfCRuntimeDll():
    This function changes the Windows execution PATH environment variable
    so as to exclude any folders that contain the file "msvcr90.dll".
    Apparently the existence of this file in the PATH causes runtime error R6034
    when using embedded Python.
    See: http://stackoverflow.com/questions/14552348/runtime-error-r6034-in-embedded-python-application
    folderPaths = os.environ['path'].split(';')
    toExclude = list()
    for folderPath in folderPaths:
        if "msvcr90.dll" in map((lambda x:x.lower()), os.listdir(folderPath)):
            debugMsg(0, "excluding folder '%s' from PATH" % folderPath)
    os.environ['path'] = ';'.join([x for x in folderPaths
                                              if x not in toExclude])
# ——————————————————————————————————————

Cameron Hayne
cameron.hayne at introspect.ca

More information about the PythonDotNet mailing list