conda-inject

1.3.2 · active · verified Thu Apr 16

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

import os
from conda_inject import inject_env

# Replace with the actual path to your conda environment
# Example: /Users/youruser/miniconda3/envs/my_env or C:\Users\youruser\miniconda3\envs\my_env
conda_env_path = os.environ.get('CONDA_ENV_PATH', '/path/to/your/conda/envs/myenv')

try:
    inject_env(conda_env_path)
    print(f"Successfully injected conda environment from: {conda_env_path}")
    # Now you can import packages from the injected environment
    # For example, if 'requests' is in myenv:
    import requests
    print(f"Successfully imported 'requests' (from injected env if present): {requests.__version__}")
except FileNotFoundError:
    print(f"Error: Conda environment path not found at {conda_env_path}")
except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →