IsaacLab icon indicating copy to clipboard operation
IsaacLab copied to clipboard

[Bug Report] Conda environment not being setup correctly for ZSH

Open j3soon opened this issue 1 year ago • 7 comments

Describe the bug

Conda environment setup script reports file not found error when using ZSH.

Steps to reproduce

Following the conda environment setup docs:

$ git clone [email protected]:isaac-sim/IsaacLab.git
$ cd IsaacLab
$ ln -s path_to_isaac_sim _isaac_sim
$ ./isaaclab.sh --conda
[INFO] Using default conda environment name: isaaclab
[INFO] Creating conda environment named 'isaaclab'...
...
$ conda activate isaaclab
/home/johnson/IsaacLab/_isaac_sim/setup_conda_env.sh:.:20: no such file or directory: /home/johnson/IsaacLab/setup_python_env.sh

System Info

Describe the characteristic of your environment:

  • Commit: 05a2f3f2b813c00bc73500f45349c0306cc8c967
  • Isaac Sim Version: 4.0.0-rc.21+4.0.13872.3e3cb0c9.gl
  • OS: Ubuntu 22.04
  • GPU: Quadro RTX 6000
  • CUDA: 12.2
  • GPU Driver: 535.183.01

Additional context

I'll open a PR for this.

Checklist

  • [x] I have checked that there is no similar issue in the repo (required)
  • [x] I have checked that the issue is not in running Isaac Sim itself and is related to the repo

Acceptance Criteria

  • [ ] Merge PR #707
  • [ ] Wait for upstream Isaac Sim fix.

j3soon avatar Jul 19 '24 10:07 j3soon

Checking with the latest Isaac Lab v2.0.1 release (with Isaac Sim 4.5.0), the ./isaaclab.sh --conda can run without error. However, another immediate error occurs:

$ git clone [email protected]:isaac-sim/IsaacLab.git
$ cd IsaacLab
$ ln -s path_to_isaac_sim _isaac_sim
$ ./isaaclab.sh --conda
[INFO] Using default conda environment name: env_isaaclab
[INFO] Creating conda environment named 'env_isaaclab'...
...
$ conda activate env_isaaclab
$ ./isaaclab.sh --install
[INFO] Installing extensions inside the Isaac Lab repository...
find: ‘/home/johnson/IsaacLab/_isaac_sim/source’: No such file or directory

This is due to the ${BASH_SOURCE[0]} used in the ./isaaclab.sh script to determine $ISAACLAB_PATH has been incorrectly changed after activating the conda environment:

$ env | grep BASH_SOURCE
$ conda activate env_isaaclab
$ env | grep BASH_SOURCE
/home/johnson/IsaacLab/_isaac_sim/setup_python_env.sh

causing the $ISAACLAB_PATH to incorrectly point to $HOME/IsaacLab/_isaac_sim (instead of the correct $HOME/IsaacLab)

The BASH_SOURCE environment variable is incorrectly modified by Isaac Sim 4.5.0 upstream script ~/isaacsim/setup_conda_env.sh. Removing the export line in setup_conda_env.sh fixes the issue:

#!/bin/bash
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [ -n "$ZSH_VERSION" ]; then
    SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
-   export BASH_SOURCE=$SCRIPT_DIR/setup_python_env.sh
fi
MY_DIR="$(realpath -s "$SCRIPT_DIR")"

On further investigation, the reason of introducing the export line above is a non-ideal fix for ~/isaacsim/setup_python_env.sh to determine its filepath when using ZSH. To fix this issue, Isaac Sim v4.0.0 -> v4.1.0 introduces this export hack.

As Isaac Sim v4.1.0 -> v4.2.0 includes a correct patch that fixed setup_python_env.sh, this hack is no longer needed after v4.2.0. This patch looks something like:

- SCRIPT_DIR="$(dirname "${BASH_SOURCE}")"
+ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

I'll keep this issue open for now, and will file a upstream issue to request removal of the export line in Isaac Sim.


Potentially related issues:

  • https://github.com/isaac-sim/IsaacLab/issues/1490
  • https://github.com/isaac-sim/IsaacLab/issues/516

j3soon avatar Feb 28 '25 16:02 j3soon

Aside from applying the fix for ~/isaacsim/setup_conda_env.sh:

#!/bin/bash
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [ -n "$ZSH_VERSION" ]; then
    SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
-   export BASH_SOURCE=$SCRIPT_DIR/setup_python_env.sh
fi
MY_DIR="$(realpath -s "$SCRIPT_DIR")"

The isaaclab.sh script should also be patched too (according to https://github.com/isaac-sim/IsaacLab/pull/707):

        printf '%s\n' \
            '# for Isaac Sim' \
-           'source '${isaacsim_setup_conda_env_script}'' \
+           'cd '${ISAACLAB_PATH}'/_isaac_sim' \
+           'source setup_conda_env.sh' \
+           'cd $OLDPWD' \
            '' >> ${CONDA_PREFIX}/etc/conda/activate.d/setenv.sh
    fi

I wonder if we should re-open PR https://github.com/isaac-sim/IsaacLab/pull/707? (or submit the same PR again?)

j3soon avatar Feb 28 '25 20:02 j3soon

Aside from applying the fix for ~/isaacsim/setup_conda_env.sh:

#!/bin/bash SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" if [ -n "$ZSH_VERSION" ]; then SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"

  • export BASH_SOURCE=$SCRIPT_DIR/setup_python_env.sh fi MY_DIR="$(realpath -s "$SCRIPT_DIR")" The isaaclab.sh script should also be patched too (according to #707):

    printf '%s\n' \
        '# for Isaac Sim' \
    
  •       'source '${isaacsim_setup_conda_env_script}'' \
    
  •       'cd '${ISAACLAB_PATH}'/_isaac_sim' \
    
  •       'source setup_conda_env.sh' \
    
  •       'cd $OLDPWD' \
          '' >> ${CONDA_PREFIX}/etc/conda/activate.d/setenv.sh
    
    fi I wonder if we should re-open PR #707? (or submit the same PR again?)

Hi, I met the same problem when I tried to install the Isaac lab with isaacsim4.5 using zsh. The error says could not find the source file under _isaac_sim folder. And I tried to follow your instructions to modify the isaaclab.sh and ~/isaacsim/setup_conda_env.sh. The problem occurs again. Could you help with fixing this installing issue?

Xunmenggod avatar Apr 22 '25 06:04 Xunmenggod

Hi @Xunmenggod, did you linked the isaacsim folder as mentioned here? https://isaac-sim.github.io/IsaacLab/main/source/setup/installation/binaries_installation.html#creating-the-isaac-sim-symbolic-link

j3soon avatar Apr 22 '25 10:04 j3soon

Hi @Xunmenggod, did you linked the isaacsim folder as mentioned here? https://isaac-sim.github.io/IsaacLab/main/source/setup/installation/binaries_installation.html#creating-the-isaac-sim-symbolic-link

Thanks for your reply. I did the step of soft link for isaac sim folder. But the same problem that could not find the source folder occurs again.

Xunmenggod avatar Apr 22 '25 10:04 Xunmenggod

Hi, I found out that the Isaac lab path env is correctly fixed after re-opening a terminal to install the Isaac lab. But there is a warning to set up the VS Code settings. [WARN] Could not find Isaac Sim VSCode settings: /home/xm-laptop/Code/issac/IsaacLab/_isaac_sim/.vscode/settings.json. This will result in missing 'python.analysis.extraPaths' in the VSCode settings, which limits the functionality of the Python language server. However, it does not affect the functionality of the Isaac Lab project. We are working on a fix for this issue with the Isaac Sim team.

And I try to look for the .vscode folder in my isaacsim folder, I found that there is no .vscode folder under my isaacsim. My Isaacsim is installed by pre-built binaries.

Xunmenggod avatar Apr 27 '25 10:04 Xunmenggod

I have the same problem. It think it's because the scrip's directory is not found correctly with zsh. I fixed it by replacing line 19 of isaaclab.sh

export ISAACLAB_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

to

if [ -n "$ZSH_VERSION" ]; then
    export ISAACLAB_PATH="$( cd "$( dirname "$0" )" &> /dev/null && pwd )"
else
    export ISAACLAB_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
fi

And replacing the line

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

in _isaac_sim/setup_conda_env.sh and _isaac_sim/setup_python_env.sh to

# Determine the script directory
if [ -n "$ZSH_VERSION" ]; then
    SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
else
    SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
fi

You then need to deactivate and reactivate your conda env. Hope this helps!

csirois14 avatar Apr 30 '25 15:04 csirois14

I resolved this issue by modifying both setup_conda_env.sh and setup_python_env.sh. The key point is that the original logic uses SCRIPT_DIR based on the runtime working directory rather than the actual script location, which causes incorrect path resolution when sourced from another shell or directory.

Here’s the fix I applied:

if [ -n "$ZSH_VERSION" ]; then
    SCRIPT_PATH="${(%):-%x}"
else
    SCRIPT_PATH="${BASH_SOURCE[0]}"
fi

SCRIPT_DIR="$( cd "$( dirname "$SCRIPT_PATH" )" && pwd )"

This ensures that SCRIPT_DIR always correctly refers to the directory where the script is located, regardless of the current terminal working directory or whether it's being sourced from bash or zsh.

Leex1 avatar May 15 '25 06:05 Leex1

  • my setup_conda_env.sh (you can copy and replace yours):
#!/bin/bash
if [ -n "$ZSH_VERSION" ]; then
    SCRIPT_PATH="${(%):-%x}"
else
    SCRIPT_PATH="${BASH_SOURCE[0]}"
fi

SCRIPT_DIR="$( cd "$( dirname "$SCRIPT_PATH" )" && pwd )"
MY_DIR="$(realpath -s "$SCRIPT_DIR")"

echo ">>> Isaac Lab environment setup"
echo "SCRIPT_DIR=$SCRIPT_DIR"

export CARB_APP_PATH="$SCRIPT_DIR/kit"
export LD_PRELOAD="$SCRIPT_DIR/kit/libcarb.so"
export EXP_PATH="$MY_DIR/apps"
export ISAAC_PATH="$MY_DIR"

SETUP_PY_ENV="$MY_DIR/setup_python_env.sh"
if [ -f "$SETUP_PY_ENV" ]; then
    source "$SETUP_PY_ENV"
else
    echo "ERROR: setup_python_env.sh not found at $SETUP_PY_ENV"
fi
  • setup_python_env.sh:
#!/bin/bash
if [ -n "$ZSH_VERSION" ]; then
    SCRIPT_PATH="${(%):-%x}"
else
    SCRIPT_PATH="${BASH_SOURCE[0]}"
fi

SCRIPT_DIR="$( cd "$( dirname "$SCRIPT_PATH" )" && pwd )"
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$SCRIPT_DIR/../../../$LD_LIBRARY_PATH:$SCRIPT_DIR/.:$SCRIPT_DIR/exts/omni.usd.schema.isaac/plugins/IsaacSensorSchema/lib:$SCRIPT_DIR/exts/omni.usd.schema.isaac/plugins/RangeSensorSchema/lib:$SCRIPT_DIR/exts/omni.isaac.lula/pip_prebundle:$SCRIPT_DIR/exts/omni.exporter.urdf/pip_prebundle:$SCRIPT_DIR/kit:$SCRIPT_DIR/kit/kernel/plugins:$SCRIPT_DIR/kit/libs/iray:$SCRIPT_DIR/kit/plugins:$SCRIPT_DIR/kit/plugins/bindings-python:$SCRIPT_DIR/kit/plugins/carb_gfx:$SCRIPT_DIR/kit/plugins/rtx:$SCRIPT_DIR/kit/plugins/gpu.foundation
export PYTHONPATH=$PYTHONPATH:$SCRIPT_DIR/../../../$PYTHONPATH:$SCRIPT_DIR/kit/python/lib/python3.10/site-packages:$SCRIPT_DIR/python_packages:$SCRIPT_DIR/exts/omni.isaac.kit:$SCRIPT_DIR/kit/kernel/py:$SCRIPT_DIR/kit/plugins/bindings-python:$SCRIPT_DIR/exts/omni.isaac.lula/pip_prebundle:$SCRIPT_DIR/exts/omni.exporter.urdf/pip_prebundle:$SCRIPT_DIR/extscache/omni.kit.pip_archive-0.0.0+10a4b5c0.lx64.cp310/pip_prebundle:$SCRIPT_DIR/exts/omni.isaac.core_archive/pip_prebundle:$SCRIPT_DIR/exts/omni.isaac.ml_archive/pip_prebundle:$SCRIPT_DIR/exts/omni.pip.compute/pip_prebundle:$SCRIPT_DIR/exts/omni.pip.cloud/pip_prebundle

Leex1 avatar May 15 '25 06:05 Leex1