{"record":{"id":"9fecb287c68f77dc","repo":"influxdata/influxdb","slug":"error-shelling-out-0","errorCode":null,"errorMessage":"Error shelling out: {0}","messagePattern":"Error shelling out: (.+?)","errorType":"exception","errorClass":"VenvError","httpStatus":null,"severity":"error","filePath":"influxdb3_processing_engine/src/virtualenv.rs","lineNumber":15,"sourceCode":"use observability_deps::tracing::debug;\nuse pyo3::Python;\nuse std::env;\nuse std::ffi::CString;\nuse std::path::{Path, PathBuf};\nuse std::sync::Once;\nuse thiserror::Error;\n\nstatic PYTHON_INIT: Once = Once::new();\n\n#[derive(Error, Debug)]\npub enum VenvError {\n    #[error(\"Failed to initialize virtualenv: {0}\")]\n    InitError(String),\n    #[error(\"Error shelling out: {0}\")]\n    CommandError(#[from] std::io::Error),\n}\n\n// Find the python installation location (not virtual env).\n// XXX: use build flag?\nfn find_python_install() -> Option<PathBuf> {\n    let influxdb3_exe = env::current_exe().unwrap();\n    let influxdb3_exe_dir = influxdb3_exe.parent().unwrap();\n    let influxdb3_rel_dir = influxdb3_exe_dir.join(\"python\");\n    let influxdb3_linux_dir = influxdb3_exe_dir.join(\"../lib/influxdb3/python\");\n\n    let python_inst = if cfg!(target_os = \"linux\")\n        && (influxdb3_exe_dir == Path::new(\"/usr/bin\")\n            || influxdb3_exe_dir == Path::new(\"/usr/local/bin\"))\n        && influxdb3_linux_dir.is_dir()\n    {\n        // Official Linux deb/rpm/docker builds are in /usr (but also allow for\n        // /usr/local) so use runtime in /usr/[local/]lib/influxdb3/python/","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/influxdata/influxdb/blob/06200ef96ba82c5f6727e5038a83af8e722c6875/influxdb3_processing_engine/src/virtualenv.rs#L1-L33","documentation":"`VenvError::CommandError` wraps a `std::io::Error` produced when the code shells out to Python (e.g. running `pip install` inside the virtualenv). It surfaces OS-level failures such as the process failing to spawn or a non-spawnable executable.","triggerScenarios":"Running virtualenv package installation (`run_pip_install`-style commands) where spawning the python subprocess fails: python binary path invalid, permissions missing, or working directory/paths bad.","commonSituations":"Venv created with a python binary later deleted or moved; PATH stripped in containerized deployments; read-only filesystem preventing pip operations; SELinux/apparmor blocking exec.","solutions":["Check that the python executable inside the venv exists and is executable (`ls -l <venv>/bin/python`).","Recreate the virtualenv if its base interpreter was removed or upgraded.","Run the server with sufficient permissions and a writable filesystem for the venv.","Inspect the wrapped io::Error (its source chain) for the OS-level cause (ENOENT, EACCES, etc.)."],"exampleFix":"// before\nCommand::new(venv_python).args([\"-m\", \"pip\", \"install\", pkg]).output()?;\n// after\nlet out = Command::new(&venv_python).args([\"-m\", \"pip\", \"install\", pkg]).output()\n    .map_err(VenvError::CommandError)\n    .context(format!(\"python binary missing at {}\", venv_python.display()))?;","handlingStrategy":"try-catch","validationCode":"// Before invoking plugin loading\nlet venv_python = Path::new(&venv_dir).join(\"bin/python\");\nif !venv_python.exists() || !is_executable(&venv_python) { /* recreate venv first */ }","typeGuard":null,"tryCatchPattern":"// Rust caller\nmatch venv.install_packages(&pkgs) {\n    Err(VenvError::CommandError(io)) => {\n        eprintln!(\"subprocess failed: {io} (source: {:?})\", io.source());\n        // check venv python exists, permissions, PATH\n    }\n    other => other?,\n}","preventionTips":["Ensure the venv's python binary exists and is executable before shelling out","Grant the server process exec permissions on the venv directory","Use a writable persistent filesystem for venvs in containers"],"tags":["python","subprocess","io","virtualenv"],"backgroundTag":"command-not-found","analyzedSha":"06200ef96ba82c5f6727e5038a83af8e722c6875","analyzedAt":"2026-09-19T12:55:30.003Z","contentChangedAt":"2026-09-19T12:55:30.003Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}