OpenHands icon indicating copy to clipboard operation
OpenHands copied to clipboard

[Bug]: Gets stuck while trying to activate virtual environment

Open anjor opened this issue 1 year ago β€’ 21 comments

Is there an existing issue for the same bug?

  • [X] I have checked the troubleshooting document at https://opendevin.github.io/OpenDevin/modules/usage/troubleshooting
  • [X] I have checked the existing issues.

Describe the bug

OpenDevin gets stuck while trying to activate an existing virtual environment.

OpenDevin often wants to install packages to be able to test locally. I would prefer it to use a virtual environment, so I usually ask it to activate the virtual environment. And I have consistently seen it get stuck:

==============
CodeActAgent LEVEL 0 STEP 1

19:55:20 - opendevin:INFO: llm.py:239 - Cost: 0.02 USD | Accumulated Cost: 0.04 USD
19:55:20 - ACTION
**CmdRunAction**
THOUGHT: Great! Now, let's activate the Python virtual environment stored in `.venv`.
COMMAND:
source .venv/bin/activate

Current OpenDevin version

ghcr.io/opendevin/opendevin:0.7

Installation and Configuration

WORKSPACE_BASE=$(pwd)/workspace
docker run -it \
    --pull=always \
    -e SANDBOX_USER_ID=$(id -u) \
    -e WORKSPACE_MOUNT_PATH=$WORKSPACE_BASE \
    -v $WORKSPACE_BASE:/opt/workspace_base \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -p 3000:3000 \
    --add-host host.docker.internal:host-gateway \
    --name opendevin-app-$(date +%Y%m%d%H%M%S) \
    ghcr.io/opendevin/opendevin:0.7

Vanilla configuration using default gpt-4o and my api key.



### Model and Agent

- Model: gpt-4o
- Agent: CodeActAgent

### Operating System

Mac OS

### Reproduction Steps

1. set up a python virtual environment in the workspace
2. Ask OpenDevin to activate the virtual environment
3. It should try to execute the command but then get stuck.

### Logs, Errors, Screenshots, and Additional Context

_No response_

anjor avatar Jul 04 '24 20:07 anjor

If you'd run the command manually, check what interactive prompt messages you get. Not sure, if you could ask the LLM to use sudo?

tobitege avatar Jul 04 '24 20:07 tobitege

When I do it from the opendevin terminal, It get's stuck the same way with nothing in the logs.

If I do it from just the native mac terminal it works.

anjor avatar Jul 04 '24 21:07 anjor

Same issue. I create a new project and it gets stuck trying to activate the environment. Apple M1, Docker Desktop w/ 26.1.4.

image

Terminal: image

Workspace directory: workspace directory: /Users/amosk/opendevin

Started with

~ % docker run -it \
    --pull=always \
    -e SANDBOX_USER_ID=$(id -u) \
    -e WORKSPACE_MOUNT_PATH=$WORKSPACE_BASE \
    -v $WORKSPACE_BASE:/opt/workspace_base \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -p 3000:3000 \
    --add-host host.docker.internal:host-gateway \
    --name opendevin-app-$(date +%Y%m%d%H%M%S) \
    ghcr.io/opendevin/opendevin:0.7

amosk avatar Jul 04 '24 22:07 amosk

OpenDevin is using miniforge3, that might be the reason. πŸ€” @Shimada666 wdyt?

tobitege avatar Jul 04 '24 22:07 tobitege

Is there any way to get more logs? How do I switch on debug logging?

anjor avatar Jul 04 '24 23:07 anjor

Hope some expert comes in here with a solution this really needs to be fixed makes doing certain things pointless.

Faultyskullslayer avatar Jul 05 '24 00:07 Faultyskullslayer

I'll try to ping some people to take a look at this ASAP.

mamoodi avatar Jul 05 '24 01:07 mamoodi

344762419-25541142-7f25-4645-895f-1b59e3ff577b Dropping a screenshot here as well of the issue

Faultyskullslayer avatar Jul 05 '24 02:07 Faultyskullslayer

It may be that the virtual environment changes the shell prompt. My first thought is that the prompt in the shell is being modified, which prevents the proper detection of command completion, similar to the following:

➜  ~
(base) ➜  ~

However, I'm not 100% sure if this is the issue.

iFurySt avatar Jul 05 '24 03:07 iFurySt

Oh yes. I have a oh-my-zsh setup that shows the current branch. So the prompt does in fact change!

anjor avatar Jul 05 '24 04:07 anjor

It may be that the virtual environment changes the shell prompt.

@iFurySt Yes - I think this is the root cause! So right now the prompt change would break pxssh's parsing logic, which would be hard to fix temporarily. A workaround we used was to set conda config --set changeps1 False before everything starts (https://github.com/OpenDevin/OpenDevin/blob/038e8f8caa3c2f5bedfd2a2d62cedf8fb309cad1/containers/sandbox/Dockerfile#L38), the it will not change the PS1 prompt hence not breaking it.

But it is not perfect, since ideally the agent should know what environment it is dealing with. The slightly long-term plan was to completely replace pxssh with pexcept in the architecture refractor (https://github.com/OpenDevin/OpenDevin/issues/2404) and write these parsing logic ourselves to try to address this completely 😒 (but this could take a while).

xingyaoww avatar Jul 05 '24 04:07 xingyaoww

@xingyaoww is there an equivalent temporary workaround for virtualenv? Right now this is the main blocker for me.

anjor avatar Jul 06 '24 07:07 anjor

@anjor

Hi anjor. We are working to make the opendevin Python runtime completely transparent to users. Once this PR #2796 is merged, the default Python will point to a clean python environment /usr/bin/python instead of the current opendevin python runtime /opendevin/miniforge3/bin/python. You will then be able to use the default python interpretor /usr/bin/python to install dependencies instead of a virtual environment. Maybe this can solve your problem.

Shimada666 avatar Jul 06 '24 09:07 Shimada666

Sorry maybe I am misunderstanding. I don't want to use the default interpreter. I would prefer to have a virtualenv per project.

Or does opendevin maintain it's own sandbox anyway?

anjor avatar Jul 06 '24 09:07 anjor

@anjor Maybe you can run each project in a different opendevin container? One container for each of your projects. This way, you won't need to use virtual environments.

Shimada666 avatar Jul 06 '24 09:07 Shimada666

Yeah that will work. Thanks!

anjor avatar Jul 06 '24 09:07 anjor

@xingyaoww just so I understand this for future. Is this an issue we want to tackle and one that should stay open?

mamoodi avatar Jul 10 '24 19:07 mamoodi

@mamoodi Yes! This is among the first batch of issues we want to address after the architecture refractor.

xingyaoww avatar Jul 10 '24 19:07 xingyaoww

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Aug 13 '24 01:08 github-actions[bot]

I attempted to run init.sh as follows. However, CUDA was not installed due to an interruption, likely caused by a timeout (43 seconds).

./workspace/requirements.txt

matplotlib
numpy
pandas
pytest
scikit-learn
scipy
torch

./workspace/init.sh

#!/bin/bash
# /workspace/init.sh

# Store original directory
ORIG_DIR=$PWD
cd /workspace

# Display user and home directory
echo $USER
echo $HOME

# Create and setup virtual environment
/opendevin/miniforge3/bin/python -m venv /home/opendevin/env
sudo chmod 7777 /home/opendevin
export VIRTUAL_ENV_DISABLE_PROMPT=1
source /home/opendevin/env/bin/activate

# Check Python and pip locations
which python
which pip

# Update pip and install requirements
pip install -U pip

if [ -f "requirements.txt" ]; then
    echo "requirements.txt found in /workspace"
    pip install -r requirements.txt 2>&1
else
    echo "requirements.txt not found in /workspace"
fi

pip freeze

# Return to original directory
cd $ORIG_DIR

# EOF

Standard Output

Downloading torch-2.4.0-cp310-cp310-manylinux1_x86_64.whl (797.2 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 797.2/797.2 MB 11.7 MB/s eta 0:00:00
Downloading nvidia_cublas_cu12-12.1.3.1-py3-none-manylinux1_x86_64.whl (410.6 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 410.6/410.6 MB 11.6 MB/s eta 0:00:00
Downloading nvidia_cuda_cupti_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (14.1 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 14.1/14.1 MB 11.4 MB/s eta 0:00:00
Downloading nvidia_cuda_nvrtc_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (23.7 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 23.7/23.7 MB 11.6 MB/s eta 0:00:00
Downloading nvidia_cuda_runtime_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (823 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 823.6/823.6 kB 12.1 MB/s eta 0:00:00
Downloading nvidia_cudnn_cu12-9.1.0.70-py3-none-manylinux2014_x86_64.whl (664.8 MB)
   ━━━━━━━╸━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 131.6/664.8 MB 11.7 MB/s eta 0:00:46
ERROR: Operation cancelled by user

ywatanabe1989 avatar Sep 01 '24 08:09 ywatanabe1989

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Oct 02 '24 01:10 github-actions[bot]

This issue was closed because it has been stalled for over 30 days with no activity.

github-actions[bot] avatar Oct 10 '24 01:10 github-actions[bot]