Skip to content

Smart IDA Python environment activator with seamless virtualenv/Conda detection, auto-path patching, and developer-friendly prompts.

License

Notifications You must be signed in to change notification settings

quippy-dev/IDAEnvOrchestrator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IDAEnvOrchestrator

Environment activation helpers for IDA Pro that automatically pick the right Python runtime (virtualenv or Conda/Mamba), patch search paths safely, and keep your IDA toolchain aligned with the packages you install.

Why This Exists

Willi Ballenthin’s March 25, 2025 write-up, "Using a virtualenv for IDAPython", documents the pain of trying to use a pure virtualenv with IDAPython: the interpreter DLL/libpython binary that idapyswitch expects is usually not sufficient, so IDA cannot fully transition to the isolated environment and crashes on startup. IDAEnvOrchestrator codifies a workflow that pairs IDA with environments that do ship the necessary runtime (Conda, micromamba, classic virtualenv seeded from a full interpreter) and automates the activation logic inside envs.py.

Features

  • Detects already-active VIRTUAL_ENV / CONDA_PREFIX so IDA respects your terminal session when launched from the shell.
  • Shared activation helpers for virtualenv and Conda/Mamba with consistent path normalization (pathlib), retries, and detailed logging.
  • Seamless prompting through idaapi.ask_str/askstr when you prefer to select an environment at startup.
  • Works from both ad-hoc console sessions and direct launching of IDA via idapythonrc.py, avoiding the need to start IDA from an already-activated shell.
  • Defensive fallbacks that leave IDA running even when activation fails, rather than breaking your session.

Installation

  1. Determine your IDA user directory (inside IDA run print(idaapi.get_user_idadir()); typically ~/.idapro or %APPDATA%\Hex-Rays\IDA Pro).
  2. Copy envs.py into that directory.
  3. Edit idapythonrc.py as described below.
  4. Restart IDA so the new helpers are imported.
# macOS/Linux example: install straight from GitHub
curl -fLo "$HOME/.idapro/envs.py" https://raw.githubusercontent.com/quippy-dev/IDAEnvOrchestrator/main/envs.py

Proven Environment Setup (micromamba + idapyswitch)

The lightweight uv install ... --default workflow highlighted in the article still lacks an adequate libpython for IDA. Conda-family distributions ship everything IDA needs, and micromamba gives you that in three quick steps:

"${SHELL}" <(curl -L micro.mamba.pm/install.sh)
micromamba create --use-uv --platform osx-arm64 python==3.10.11 --prefix ~/.idapro/venv
idapyswitch -s "$HOME/micromamba/lib/libpython3.10.dylib"

Replace the shared library path with the one produced by your micromamba install (or Windows .dll / Linux .so), and always adjust the idapyswitch path.

Required: Always run idapyswitch -s /full/path/to/libpython3.x.{dylib|so|dll} so IDA links against the same runtime that seeded your environment packages. Minimal interpreter stubs (including uv installations) will crash IDA.

Configuring idapythonrc.py

Once envs.py is in place, add the contents of the repo’s idapythonrc.py to $IDAUSR/idapythonrc.py and enable whichever call pattern suits your setup:

from envs import detect_env, activate_conda_env, activate_virtualenv_env

# Option 1: auto-detect via env vars, retrying when needed
if not detect_env():
    print("IDAEnvOrchestrator: no environment activated; using stock interpreter.")

# Option 2: enforce a virtualenv relative to $IDAUSR
# detect_env(".venv")

# Option 3: Conda/Mamba helpers
envs_path = "venv"  # directory under $IDAUSR (or pass base=/absolute/prefix)
try:
    env_path = activate_conda_env(env=envs_path, interactive=False)
    print(f"IDAEnvOrchestrator: using Conda prefix at {env_path}")
except ValueError as exc:
    print(f"IDAEnvOrchestrator: conda activation fallback triggered: {exc}")
# activate_conda_env(env=None)  # prompt each startup

# Option 4: Virtualenv helpers
# activate_virtualenv_env(virtualenv="virtualenv")
# activate_virtualenv_env(virtualenv=None)  # prompt each startup

You can still trigger activation manually from the IDA Python console:

from envs import detect_env
if not detect_env():
    print("No environment detected; check log output.")

Usage Notes

  • Match interpreter versions: if your virtualenv/Conda env targets 3.10, ensure IDA is currently configured via idapyswitch for the corresponding Python 3.10 libpython.
  • When using micromamba or Conda, the helper adds both <env>/bin and <env>/Scripts (Windows) to PATH and pushes new site-packages entries to the top of sys.path without losing the previous ordering.
  • detect_env() retries with default parameters after a failed explicit attempt, so you can provide preferred names without breaking auto-discovery.

Troubleshooting

  • “No conda env detected in …” – Confirm the prefix contains a conda-meta/ subdirectory and that IDA points to the matching libpython3.x via idapyswitch -s.
  • Missing activate_this.py – Recreate the environment with python -m virtualenv <path>; the bare venv module omits the activator file that IDA requires.
  • IDA crashes on start – Usually indicates IDA is still bound to a different/insufficient libpython than the one that built your packages. Re-run idapyswitch -s /path/to/libpython to re-sync.

Credits

These resources shaped the workflow that IDAEnvOrchestrator refines and automates.

About

Smart IDA Python environment activator with seamless virtualenv/Conda detection, auto-path patching, and developer-friendly prompts.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages