Import idapro in the GUI exits IDA without saving

I was going to import ida_ida but by mistake wrote import idapro and then IDA shutdown without saving my database.

This was from inside IDA Pro 9.4 with GUI up on a Windows 10.

What version is your idapro module and how did you install it? Normally, it should have this check at the start of __init__.py:

_main = sys.modules.get("__main__")
if _main is not None and getattr(_main, "IDAPYTHON_VERSION", None) is not None:
    raise ImportError("The IDA library can only be run in a separate process and cannot be loaded within IDA itself.")

I’m on 0.0.10 which is the latest pip gave me. What happens when you run it in the GUI?

Here’s what happens normally:

Python>import idapro
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Python311\Lib\site-packages\idapro\__init__.py", line 16, in <module>
    raise ImportError("The IDA library can only be run in a separate process and cannot be loaded within IDA itself.")
ImportError: The IDA library can only be run in a separate process and cannot be loaded within IDA itself.

You can use importlib to check what specific lbrary it’s trying to import:

Python>import importlib
Python>importlib.util.find_spec("idapro").origin
'C:\\Python311\\Lib\\site-packages\\idapro\\__init__.py'

I found the problem. It was that IKernel set sys.modules["__main__"] but I added the IDAPYTHON_VERSION so it’s all good now :slight_smile: