codex icon indicating copy to clipboard operation
codex copied to clipboard

Pyenv shim already exists. Commands constantly timeout in WSL2 environment

Open samargy opened this issue 1 year ago • 12 comments

What version of Codex is running?

codex-cli 0.36.0

Which model were you using?

gpt-5-codex-medium

What platform is your computer?

Linux 6.6.87.2-microsoft-standard-WSL2 x86_64 x86_64

What steps can reproduce the bug?

Get codex to attempt to run any command.

What is the expected behavior?

Command runs fine.

What do you see instead?

$ rg "class Post" -n my_repo/models -g"*.py" command timed out after 60285 milliseconds pyenv: cannot rehash: /home/MY_USER/.pyenv/shims/.pyenv-shim exists ✗ (124) • 1m 00s

Additional information

I have made attempts of deleting pyenv, reinstalling. Rehashing etc.

samargy avatar Sep 19 '25 01:09 samargy

There is the same issue here. However, I noticed that it only gets triggered when running node or python scripts. It always times out and throws an error after one minute:

pyenv: cannot rehash: /home/username/.pyenv/shims/.pyenv-shim exists

Jannchie avatar Sep 29 '25 11:09 Jannchie

Yep this is exactly my experience. Anything that you found that fixes this issue?

Still occuring with codex 0.41.0

samargy avatar Sep 30 '25 00:09 samargy

The solution is to uninstall pyenv. In fact, codex does not depend on pyenv; it simply cannot work in an environment configured with pyenv. If you remove all pyenv-related lines from your ~/.bashrc (or possibly ~/.zshrc), you should be able to bypass this issue.

Jannchie avatar Oct 01 '25 17:10 Jannchie

Uninstalling pyenv was a bit overkill for me (I still need it for my python stuff), but I added a command to my project Makefile to launch codex without pyenv.

.PHONY: codex-nopyenv

codex-nopyenv:
	@unset PYENV_VERSION PYENV_ROOT; \
		export PATH="$$(printf "%s" "$$PATH" | tr ":" "\n" | grep -vE "^$$HOME/.pyenv|^/mnt/c" | paste -sd: -)"; \
		if ! command -v python >/dev/null 2>&1 && command -v python3 >/dev/null 2>&1; then \
			alias python=python3; \
		fi; \
		exec codex

Sometimes, codex calls bash -lc, so I also added a guard to my .profile to avoid enabling pyenv for non interactive shells :

# Init pyenv only for interactive shells : pyenv will be initialized only if the shell is interactive
if [ -n "$BASH_VERSION" ]; then
  case $- in
    *i*)
      if [ -d "$HOME/.pyenv" ] && command -v pyenv >/dev/null 2>&1; then
        export PYENV_ROOT="$HOME/.pyenv"
        export PATH="$PYENV_ROOT/bin:$PATH"
        eval "$(pyenv init -)"
      fi
      ;;
  esac
fi

hugoJuhel avatar Oct 02 '25 15:10 hugoJuhel

I met same issue and fixed (validated by prompting codex to search certain lines in codebase) by deleting duplicated pyenv initializing scripts in ~/.bashrc ~/.profile

Environment

  • WSL2 Debian 12 (checked via cat /etc/os-release)
  • pyenv 2.5.1 (checked via pyenv --version)
  • Codex CLI installed via Homebrew
  • Was previously initializing pyenv in ~/.zshrc + ~/.bashrc + ~/.profile

Script to detect duplication

#!/usr/bin/env bash

CONFIG_FILES=(
  "$HOME/.zshrc"
  "$HOME/.bashrc"
  "$HOME/.bash_profile"
  "$HOME/.profile"
)

echo "🔍 Scanning for pyenv initialization..."

for file in "${CONFIG_FILES[@]}"; do
  if [ -f "$file" ]; then
    if grep -qE 'pyenv|PYENV_ROOT' "$file"; then
      echo "⚠️  Found pyenv config in: $file"
      grep -nE 'pyenv|PYENV_ROOT' "$file"
      echo
    else
      echo "✅ No pyenv config in: $file"
    fi
  else
    echo "ℹ️  Skipping missing file: $file"
  fi
done

echo "Done."

s3d-i avatar Oct 20 '25 11:10 s3d-i

我也遇到了同样的问题,并通过删除 ~/.bashrc 和 ~/.profile 中重复的 pyenv 初始化脚本解决了这个问题(已通过 Codex 搜索代码库中的特定行验证)。

环境

  • WSL2 Debian 12(通过 cat /etc/os-release 检查)
  • pyenv 2.5.1(通过 pyenv --version 检查)
  • 通过 Homebrew 安装的 Codex CLI
  • 之前在 ~/.zshrc + ~/.bashrc + ~/.profile 中初始化 pyenv

用于检测重复项的脚本

#!/usr/bin/env bash

CONFIG_FILES=(
  "$HOME/.zshrc"
  "$HOME/.bashrc"
  "$HOME/.bash_profile"
  "$HOME/.profile"
)

echo "🔍 Scanning for pyenv initialization..."

for file in "${CONFIG_FILES[@]}"; do
  if [ -f "$file" ]; then
    if grep -qE 'pyenv|PYENV_ROOT' "$file"; then
      echo "⚠️  Found pyenv config in: $file"
      grep -nE 'pyenv|PYENV_ROOT' "$file"
      echo
    else
      echo "✅ No pyenv config in: $file"
    fi
  else
    echo "ℹ️  Skipping missing file: $file"
  fi
done

echo "Done."

Yes, keeping only one pyenv configuration in ~/.bashrc will fix this issue.

  1. First, add the commands to `~/.bashrc` by running the following in your terminal:

      ```bash
      echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
      echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
      echo 'eval "$(pyenv init - bash)"' >> ~/.bashrc
      ```

mizuikki avatar Oct 30 '25 08:10 mizuikki

Met the same issue. Codex was way too slow until I removed pyenv initialization from the ~/.profile. Thx a lot!

mechanovkirill avatar Nov 28 '25 10:11 mechanovkirill

The timeout issue has been fixed in pyenv 2.6.16:

https://github.com/pyenv/pyenv/releases/tag/v2.6.16

Easiest way to update pyenv to the latest version is to run the following command from your terminal window:

pyenv update

For more information on the cause and resolution of the issue, see:

  • https://github.com/pyenv/pyenv/issues/3365
  • https://github.com/pyenv/pyenv/pull/3367

vlasky avatar Dec 06 '25 01:12 vlasky

This bug report hasn't received any upvotes or additional posts in four months. Closing.

etraut-openai avatar Mar 29 '26 16:03 etraut-openai

Could this be reopened? Unfortunately it's still happening on to me on MacOS w/ 2.6.20 :/

❯ pyenv: cannot rehash: couldn't acquire lock /Users/ME/.pyenv/shims/.pyenv-shim for 60 seconds. Last error message:
/opt/homebrew/Cellar/pyenv/2.6.20/libexec/pyenv-rehash: line 22: /Users/ME/.pyenv/shims/.pyenv-shim: cannot overwrite existing file

HeroCC avatar Apr 08 '26 17:04 HeroCC

@HeroCC, this bug report is very outdated at this point. If you're seeing similar symptoms with the latest release, please open a new bug report and provide all of the information in the bug template. For a bug like this, /feedback is also useful.

etraut-openai avatar Apr 08 '26 18:04 etraut-openai

Will do, ty!

HeroCC avatar Apr 08 '26 18:04 HeroCC