Registry / devops / conda-inject

conda-inject

JSON →
library1.3.2pypiunverified

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-inject
INSTALL
IMPORT
SIG · CONDA-INJECT
C
conda-inject
devopsenv1.3.2
Install
1.7s avg
Import
208ms
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.3.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.213s · 19.9MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.7s · import 0.202s · 21MB
18MB installed
● package 18MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

inject_env
from conda_inject import inject_env
Main function to inject a conda environment into sys.path.

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}")
Debug
Known issues
gotchaConda-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.
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.
affects: All versions
gotchaInjecting 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.
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.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'some_package'
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.
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`.
Python interpreter shows a different version than the injected conda environment's Python.
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.
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`.
Upgrade
Version history
1.3.2latest on PyPI · released May 27, 2024
Audit
Dependencies
pythonrequiredRuntime dependency, specifies compatible Python versions.
Agent activity
8 hits · last 30 days
node
8
Resources

No resource links recorded.

conda-inject — pip install conda-inject · libregistry