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.
pip install conda-injectVerified import paths — ran on the pinned version, not inferred.
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.
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.
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.
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`.
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`.
No resource links recorded.