Pyenv shim already exists. Commands constantly timeout in WSL2 environment

Resolved 💬 12 comments Opened Sep 19, 2025 by samargy Closed Mar 29, 2026
💡 Likely answer: A maintainer (etraut-openai, contributor) responded on this thread — see the highlighted reply below.

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.

View original on GitHub ↗

12 Comments

Jannchie · 9 months ago

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
samargy · 9 months ago

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

Still occuring with codex 0.41.0

Jannchie · 9 months ago

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.

hugoJuhel · 9 months ago

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
s3d-i · 9 months ago

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."
mizuikki · 8 months ago
我也遇到了同样的问题,并通过删除 ~/.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
``

````

mechanovkirill · 7 months ago

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

vlasky · 7 months ago

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:

etraut-openai contributor · 3 months ago

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

HeroCC · 3 months ago

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
etraut-openai contributor · 3 months ago

@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.

HeroCC · 3 months ago

Will do, ty!