{"id":14506,"library":"conda-inject","title":"conda-inject","description":"Conda-inject provides helper functions for dynamically injecting a specified conda environment into the current Python environment. It achieves this by modifying `sys.path`, allowing access to packages within the target conda environment without fully activating it in the shell. The library aims to simplify the use of conda environments in scripts and applications where a full shell activation might be cumbersome. Version 1.3.2 was released on May 27, 2024, indicating an active development status with several minor releases in the past year.","status":"active","version":"1.3.2","language":"en","source_language":"en","source_url":"https://github.com/koesterlab/conda-inject","tags":["conda","environment management","sys.path","runtime","environments"],"install":[{"cmd":"pip install conda-inject","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Runtime dependency, specifies compatible Python versions.","package":"python","optional":false}],"imports":[{"note":"Main function to inject a conda environment into sys.path.","symbol":"inject_env","correct":"from conda_inject import inject_env"}],"quickstart":{"code":"import os\nfrom conda_inject import inject_env\n\n# Replace with the actual path to your conda environment\n# Example: /Users/youruser/miniconda3/envs/my_env or C:\\Users\\youruser\\miniconda3\\envs\\my_env\nconda_env_path = os.environ.get('CONDA_ENV_PATH', '/path/to/your/conda/envs/myenv')\n\ntry:\n    inject_env(conda_env_path)\n    print(f\"Successfully injected conda environment from: {conda_env_path}\")\n    # Now you can import packages from the injected environment\n    # For example, if 'requests' is in myenv:\n    import requests\n    print(f\"Successfully imported 'requests' (from injected env if present): {requests.__version__}\")\nexcept FileNotFoundError:\n    print(f\"Error: Conda environment path not found at {conda_env_path}\")\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n","lang":"python","description":"This quickstart demonstrates how to inject a conda environment using `inject_env` and then import a package that is expected to be present within that environment. Remember to replace `/path/to/your/conda/envs/myenv` with the actual path to your desired conda environment."},"warnings":[{"fix":"Understand that `conda-inject` is primarily for Python package accessibility. For full shell activation (e.g., for executables or environment variables set by `conda activate`), use `subprocess.run(['conda', 'run', '-n', 'myenv', 'your_command'])` or activate the environment manually in the shell before running Python.","message":"Conda-inject modifies `sys.path` but does not perform full shell environment activation (e.g., setting environment variables or modifying the shell prompt). This means tools or scripts relying on an 'activated' shell environment might not behave as expected.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Prefer injecting environments that use the same major Python version as the current interpreter. If conflicts occur, inspect `sys.path` and the `conda env list` output for both environments. Consider creating isolated environments with only necessary packages to minimize conflicts.","message":"Injecting environments with different major Python versions or highly conflicting dependencies can lead to runtime errors or unexpected behavior due to `sys.path` order and incompatible shared libraries.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Verify the `conda_env_path` provided to `inject_env` points directly to the root of the conda environment (e.g., `/opt/miniconda3/envs/myenv`). Ensure 'some_package' is indeed installed in that specific conda environment using `conda list -n myenv` or `conda list -p /path/to/myenv`.","cause":"The package 'some_package' is installed in the target conda environment, but the `inject_env` call did not correctly add the environment's `site-packages` to `sys.path`, or the environment path provided was incorrect.","error":"ModuleNotFoundError: No module named 'some_package'"},{"fix":"This is expected behavior. If you need to *switch* the Python interpreter, you must activate the conda environment in your shell *before* running the Python script, or use a tool like `conda run -n myenv python my_script.py`.","cause":"Conda-inject modifies `sys.path` to include packages, but it does not change the Python interpreter that initiated the script. If your script started with Python 3.9 and you inject an environment with Python 3.10, `sys.version` will still reflect 3.9.","error":"Python interpreter shows a different version than the injected conda environment's Python."}],"ecosystem":"pypi"}