Usually this issue happens with hardware(cpu)/software(os, service pack, etc.) compatibility when you run the exe on different machine.
In your case, it's more likely because different runtime dlls are used when switching to EXE from IDE. The cause of the runtime dll returning the error maybe is a piece of code in your program. IMHO, it's hard... it takes times to figure it out whether your code or not. Possibly the cause is a bug in runtime dlls or the library dlls the program using, as you said, it's enviroment issue.
Most likely, the P-Code EXE could run without error. If you don't mind, you may settle with P-Code.
Good Luck!