dynamic conda finding
This commit is contained in:
@@ -25,3 +25,5 @@ mim install "mmpose==1.2.0"
|
|||||||
pip install "numpy<2"
|
pip install "numpy<2"
|
||||||
pip install "opencv-python==4.11.0.86"
|
pip install "opencv-python==4.11.0.86"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**This installation is referenced in each launchfile by finding the location of your conda base environment, then finding an environment named "mmpose" - if you use a different name, you must change each launch file.**
|
||||||
66
tracking_re_id/launch/_conda_utils.py
Normal file
66
tracking_re_id/launch/_conda_utils.py
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
"""Utilities for locating conda-environment Python interpreters at launch time."""
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def find_conda_python(env_name: str) -> str:
|
||||||
|
"""Return the path to ``python3`` inside a named conda environment.
|
||||||
|
|
||||||
|
Resolution order
|
||||||
|
----------------
|
||||||
|
1. ``<ENV_NAME_UPPER>_PYTHON`` environment variable (explicit override).
|
||||||
|
e.g. for *mmpose*: ``MMPOSE_PYTHON=/path/to/python3``
|
||||||
|
2. ``CONDA_EXE`` environment variable — set by ``conda init`` and points to
|
||||||
|
the conda binary inside the base installation. The base directory is two
|
||||||
|
levels up (``<base>/bin/conda → <base>``).
|
||||||
|
3. A scan of common conda base-directory locations.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
env_name:
|
||||||
|
Name of the conda environment (e.g. ``"mmpose"``).
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
str
|
||||||
|
Absolute path to the Python 3 interpreter.
|
||||||
|
|
||||||
|
Raises
|
||||||
|
------
|
||||||
|
FileNotFoundError
|
||||||
|
If no interpreter is found through any of the above methods.
|
||||||
|
"""
|
||||||
|
# 1. Explicit override via environment variable
|
||||||
|
override_var = f"{env_name.upper()}_PYTHON"
|
||||||
|
if p := os.environ.get(override_var):
|
||||||
|
return p
|
||||||
|
|
||||||
|
rel = os.path.join("envs", env_name, "bin", "python3")
|
||||||
|
|
||||||
|
# 2. Derive conda base from CONDA_EXE (most reliable when conda is initialised)
|
||||||
|
if conda_exe := os.environ.get("CONDA_EXE"):
|
||||||
|
base = os.path.dirname(os.path.dirname(conda_exe))
|
||||||
|
candidate = os.path.join(base, rel)
|
||||||
|
if os.path.isfile(candidate):
|
||||||
|
return candidate
|
||||||
|
|
||||||
|
# 3. Scan common install locations
|
||||||
|
common_bases = [
|
||||||
|
"~/miniconda3",
|
||||||
|
"~/anaconda3",
|
||||||
|
"~/mambaforge",
|
||||||
|
"~/miniforge3",
|
||||||
|
"~/opt/miniconda3",
|
||||||
|
"/opt/conda",
|
||||||
|
"/opt/miniconda3",
|
||||||
|
"/opt/anaconda3",
|
||||||
|
]
|
||||||
|
for base in common_bases:
|
||||||
|
candidate = os.path.join(os.path.expanduser(base), rel)
|
||||||
|
if os.path.isfile(candidate):
|
||||||
|
return candidate
|
||||||
|
|
||||||
|
raise FileNotFoundError(
|
||||||
|
f"Cannot locate Python for conda env '{env_name}'. "
|
||||||
|
f"Set the {override_var} environment variable to the full path of the interpreter."
|
||||||
|
)
|
||||||
@@ -15,14 +15,17 @@ To view the annotated image:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
sys.path.insert(0, os.path.dirname(__file__))
|
||||||
|
from _conda_utils import find_conda_python # noqa: E402
|
||||||
|
|
||||||
from launch import LaunchDescription
|
from launch import LaunchDescription
|
||||||
from launch.actions import ExecuteProcess
|
from launch.actions import ExecuteProcess
|
||||||
|
|
||||||
|
|
||||||
def generate_launch_description():
|
def generate_launch_description():
|
||||||
python_exe = os.path.expanduser(
|
python_exe = find_conda_python('mmpose')
|
||||||
'~/miniconda3/envs/mmpose/bin/python3'
|
|
||||||
)
|
|
||||||
|
|
||||||
return LaunchDescription([
|
return LaunchDescription([
|
||||||
|
|
||||||
|
|||||||
@@ -6,14 +6,17 @@ Python environment.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
sys.path.insert(0, os.path.dirname(__file__))
|
||||||
|
from _conda_utils import find_conda_python # noqa: E402
|
||||||
|
|
||||||
from launch import LaunchDescription
|
from launch import LaunchDescription
|
||||||
from launch.actions import ExecuteProcess
|
from launch.actions import ExecuteProcess
|
||||||
|
|
||||||
|
|
||||||
def generate_launch_description():
|
def generate_launch_description():
|
||||||
python_exe = os.path.expanduser(
|
python_exe = find_conda_python('mmpose')
|
||||||
'~/miniconda3/envs/mmpose/bin/python3'
|
|
||||||
)
|
|
||||||
|
|
||||||
return LaunchDescription([
|
return LaunchDescription([
|
||||||
|
|
||||||
|
|||||||
@@ -6,12 +6,17 @@ To view output:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
sys.path.insert(0, os.path.dirname(__file__))
|
||||||
|
from _conda_utils import find_conda_python # noqa: E402
|
||||||
|
|
||||||
from launch import LaunchDescription
|
from launch import LaunchDescription
|
||||||
from launch.actions import ExecuteProcess
|
from launch.actions import ExecuteProcess
|
||||||
|
|
||||||
|
|
||||||
def generate_launch_description():
|
def generate_launch_description():
|
||||||
python_exe = os.path.expanduser('~/miniconda3/envs/mmpose/bin/python3')
|
python_exe = find_conda_python('mmpose')
|
||||||
keyreID_path = os.path.expanduser('~/KeyRe-ID')
|
keyreID_path = os.path.expanduser('~/KeyRe-ID')
|
||||||
|
|
||||||
return LaunchDescription([
|
return LaunchDescription([
|
||||||
|
|||||||
@@ -23,12 +23,17 @@ Viewing the output
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
sys.path.insert(0, os.path.dirname(__file__))
|
||||||
|
from _conda_utils import find_conda_python # noqa: E402
|
||||||
|
|
||||||
from launch import LaunchDescription
|
from launch import LaunchDescription
|
||||||
from launch.actions import ExecuteProcess
|
from launch.actions import ExecuteProcess
|
||||||
|
|
||||||
|
|
||||||
def generate_launch_description():
|
def generate_launch_description():
|
||||||
python_exe = os.path.expanduser('~/miniconda3/envs/mmpose/bin/python3')
|
python_exe = find_conda_python('mmpose')
|
||||||
keyreID_path = os.path.expanduser('~/KeyRe-ID')
|
keyreID_path = os.path.expanduser('~/KeyRe-ID')
|
||||||
|
|
||||||
return LaunchDescription([
|
return LaunchDescription([
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
"""Launch single_person_loc_node using the mmpose conda environment's Python."""
|
"""Launch single_person_loc_node using the mmpose conda environment's Python."""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
sys.path.insert(0, os.path.dirname(__file__))
|
||||||
|
from _conda_utils import find_conda_python # noqa: E402
|
||||||
|
|
||||||
from launch import LaunchDescription
|
from launch import LaunchDescription
|
||||||
from launch.actions import ExecuteProcess
|
from launch.actions import ExecuteProcess
|
||||||
|
|
||||||
|
|
||||||
def generate_launch_description():
|
def generate_launch_description():
|
||||||
python_exe = os.path.expanduser(
|
python_exe = find_conda_python('mmpose')
|
||||||
'~/miniconda3/envs/mmpose/bin/python3'
|
|
||||||
)
|
|
||||||
|
|
||||||
node_module = 'tracking_re_id.single_person_loc_node'
|
node_module = 'tracking_re_id.single_person_loc_node'
|
||||||
|
|
||||||
|
|||||||
@@ -6,14 +6,17 @@ pipeline where visualisation is handled elsewhere.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
sys.path.insert(0, os.path.dirname(__file__))
|
||||||
|
from _conda_utils import find_conda_python # noqa: E402
|
||||||
|
|
||||||
from launch import LaunchDescription
|
from launch import LaunchDescription
|
||||||
from launch.actions import ExecuteProcess
|
from launch.actions import ExecuteProcess
|
||||||
|
|
||||||
|
|
||||||
def generate_launch_description():
|
def generate_launch_description():
|
||||||
python_exe = os.path.expanduser(
|
python_exe = find_conda_python('mmpose')
|
||||||
'~/miniconda3/envs/mmpose/bin/python3'
|
|
||||||
)
|
|
||||||
|
|
||||||
node_module = 'tracking_re_id.single_person_loc_node'
|
node_module = 'tracking_re_id.single_person_loc_node'
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user