IDA PYTHONHOME wrapper (last update: 2017-11-12, created: 2017-11-12) back to the list ↑
In case you get the following error (which happens if for any reason 32-bit IDA finds 64-bit libraries for Python modules, or 64-bit IDA finds 32-bit libraries for Python modules):


...\loaders\uimage.py: DLL load failed: %1 is not a valid Win32 application.
Traceback (most recent call last):
  File "...\python\ida_idaapi.py", line 509, in IDAPython_ExecScript
    execfile(script, g)
  File ".../loaders/uimage.py", line 54, in <module>
    import ctypes
  File "...\python2714_64\Lib\ctypes\__init__.py", line 7, in <module>
    from _ctypes import Union, Structure, Array
ImportError: DLL load failed: %1 is not a valid Win32 application.

You need to set PYTHONHOME environment variable to point to the proper Python directory (32- or 64-bit, depending on what IDA needs).

If you can't set the above variable globally, you can use a short Python wrapper script (you actually need two, for idaq.exe and idaq64.exe), e.g.:


import os
import subprocess
import sys
os.environ['PYTHONHOME'] = 'd:\\path_to_good_python_version\\'
subprocess.call(['d:\\path_to_IDA\\idaq64.exe'] + sys.argv[1:])  # Or without "64" there.

Name it e.g. idaq_wrapper.pyw, so that a console window doesn't pop-up.
【 design & art by Xa / Gynvael Coldwind 】 【 logo font (birdman regular) by utopiafonts / Dale Harris 】