Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Runtime error R6034 in embedded Python application

I am working on an application which uses Boost.Python to embed the Python interpreter. This is used to run user-generated "scripts" which interact with the main program.

Unfortunately, one user is reporting runtime error R6034 when he tries to run a script. The main program starts up fine, but I think the problem may be occurring when python27.dll is loaded.

I am using Visual Studio 2005, Python 2.7, and Boost.Python 1.46.1. The problem occurs only on one user's machine. I've dealt with manifest issues before, and managed to resolve them, but in this case I'm at a bit of a loss.

Has anyone else run into a similar problem? Were you able to solve it? How?

like image 314
Michael Cooper Avatar asked Jan 27 '13 21:01

Michael Cooper


2 Answers

I found the solution to the problem. Hopefully this will help someone else--these problems can be so frustrating to debug.

The problem was caused by third-party software that had added itself to the path and installed msvcr90.dll in its program folder. In this case, the problem was caused by Intel's iCLS Client.

So... How to find the problem in similar situations?

  1. Download Process Explorer here.

  2. Start your application and reproduce runtime error R6034.

  3. Start Process Explorer. In the "View" menu go to "Lower Pane View" and choose "DLLs".

  4. In the top pane, locate your application and click on it. The bottom pane should show a list of DLLS loaded for your application.

  5. Locate "msvcr??.dll" in the list. There should be several. Look for the one that is not in the "winsxs" folder, and make a note of it.

  6. Now, check the path just before your application runs. If it includes the folder you noted in step 5, you've probably found the culprit.

How to fix the problem? You'll have to remove the offending entry from the path before running your program. In my case, I don't need anything else in the path, so I wrote a simple batch file that looks like this:

path=
myprogram.exe

That's it. The batch file simply clears the path before my program runs, so that the conflicting runtime DLL is not found.

Hope this helps!

like image 141
Michael Cooper Avatar answered Nov 05 '22 09:11

Michael Cooper


This post elaborates on @Micheal Cooper and @frmdstryr and gives a better alternative than my earlier answer. You can put the following in front of a python script to purge the problematic entries.

import os, re
path = os.environ['PATH'].split(';')

def is_problem(folder):
    try:
        for item in os.listdir(folder):
            if re.match(r'msvcr\d\d\.dll', item):
                return True
    except:
        pass
    return False

path = [folder for folder in path if not is_problem(folder)]
os.environ['PATH'] = ';'.join(path)

For the vim with YouCompleteMe case, you can put the following at the top of your vimrc:

python << EOF
import os, re
path = os.environ['PATH'].split(';')

def is_problem(folder):
    try:
        for item in os.listdir(folder):
            if re.match(r'msvcr\d\d\.dll', item):
                return True
    except:
        pass
    return False

path = [folder for folder in path if not is_problem(folder)]
os.environ['PATH'] = ';'.join(path)
EOF
like image 6
chtenb Avatar answered Nov 05 '22 10:11

chtenb