Repository navigation
Description
This morning when I logged in after an OS update (MacOS Sonoma 14.1) I got -bash: python: command not found in all my restarted terminals.
In one of them, I could also see
pyenv: cannot rehash: /Users/fsc-eriker/.pyenv/shims/.pyenv-shim exists
Of course, the file no longer existed by the time I checked.
Running pyenv rehash in one of the terminals resolved the problem in all of them.
My suspicion is that there is a race condition when many terminals start up in quick succession after a reboot, though I have been running pyenv for several years and this is the first time I see this problem.
Prerequisite
- Make sure your problem is not listed in the common build problems.
- Make sure no duplicated issue has already been reported in the pyenv issues. You should look for closed issues, too.
- Make sure you are not asking us to help solving your specific issue.
- GitHub issues is opened mainly for development purposes. If you want to ask someone to help solving your problem, go to some community site like Gitter, StackOverflow, etc.
- Make sure your problem is not derived from packaging (e.g. Homebrew).
- Please refer to the package documentation for the installation issues, etc.
- Make sure your problem is not derived from plugins.
- This repository is maintaining
pyenvand the defaultpython-buildplugin only. Please refrain from reporting issues of other plugins here.
- This repository is maintaining
Description
- Platform information: MacOS 14.1
- OS architecture (e.g. amd64): Intel
- pyenv version: 2.3.17
- Python version: 3.11.3 (among others)
- C Compiler information (e.g. gcc 7.3): clang I guess? I have 15.0.0
- Please attach the debug trace of the failing command as a gist:
- Run
env PYENV_DEBUG=1 <faulty command> 2>&1 | tee trace.logand attachtrace.log. E.g. if you have a problem with installing Python, runenv PYENV_DEBUG=1 pyenv install -v <version> 2>&1 | tee trace.log(note the-voption topyenv install).
- Run
- If you have a problem with installing Python, please also attach
config.logfrom the build directory- The build directory is reported after the "BUILD FAILED" message and is usually under
/tmp.
- The build directory is reported after the "BUILD FAILED" message and is usually under
- If the build succeeds but the problem is still with the build process (e.g. the resulting Python is missing a feature), please attach
- the debug trace from reinstalling the faulty version with
env PYENV_DEBUG=1 pyenv install -f -k -v <version> 2>&1 | tee trace.log config.logfrom the build directory. When usingpyenv installwith-kas per above, the build directory will be under$PYENV_ROOT/sources.
- the debug trace from reinstalling the faulty version with
I have pyenv-virtualenv plugin but I imagine it is not involved in this issue. Unfortunately, because there is no way to repro reliably, I cannot rule out that this is caused by Homebrew or the plugin or etc.
Several old issues seem related but too old to be directly relevant as duplicates; #1092, #1145, maybe #1137 and #1747.
Activity
native-api commentedon Oct 28, 2023
That's exactly it.
Does that cause a problem though? All terminal instances should be fine if at least one rehash has succeeded.
native-api commentedon Oct 28, 2023
touch "${PYENV_ROOT}/shims/.pyenv-shim"That's what one of our tests uses to model this situation.
fsc-eriker commentedon Oct 30, 2023
Indeed, the ticket is about a case where this did not happen, i.e. none of the terminal instances was fine (as far as I was able to check; I did not individually review more than 5-6 -- I'm guessing maybe one of them must have succeeded eventually, but which one?)
fsc-eriker commentedon Oct 30, 2023
As a tentative workaround I changed my
.bashrcto runeval "$(pyenv init - --no-rehash)"and instead set up a separate login item to runeval "$(pyenv init -)"just once. I don't think I can know whether it works until much later.native-api commentedon Nov 1, 2023
I cannot reproduce the problem.
pyenv-rehashis designed for this situation: it uses a lock file and waits with a 60 second timeout if it's already held before bailing out.Moreover, the stock startup code silences error messages from
pyenv rehash. So you may have local customizations in place.Make sure you have the latest, stock version of Pyenv.
If it's still a problem, please provide the debug trace demonstrating the problem as per the issue template.
github-actions commentedon Dec 1, 2023
This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.
rsantellan commentedon Jan 31, 2024
After installing on LMDE 6 (Debian 12) I'm having the same problem, on startup guake is started an when I try to open a terminal it shows on guake:
pyenv: cannot rehash: ~/.pyenv/shims/.pyenv-shim existsIs pretty common issue for me (I turn off the laptop every day and work mainly with a terminal).
How can I provide more information to this issue ?
native-api commentedon Jan 31, 2024
@rsantellan Use the issue template to provide the information necessary to diagnose a problem. It appears when you create a new issue.
sasa-buklijas commentedon Oct 18, 2024
just FYI
I had same problem because machine had 1% free ssd space.
it was remote (ssh only) server for testing
techwizrd commentedon May 16, 2026
I’m seeing what looks like the same failure mode on macOS with a newer pyenv, but with a more visible shell-startup impact.
Environment:
What happens:
pyenv initduring shell startuppyenv initemitscommand pyenv rehashpyenv rehashthen waits the full 60 second timeout trying to acquire the shim lock/prototype fileObserved error:
In my case, the file was still present after the failure:
This looks like a stale/orphaned lock/prototype file case, not a sandbox writability issue.
Measurements:
fish --no-config -i -c exit: about0.01sfish -i -c exitbefore fix: about60.6s.pyenv-shimand changing shell init topyenv init - --no-rehash fish | source: about0.28sto0.34sSo there seem to be two separate concerns:
.pyenv-shimcan blockpyenv rehashfor the full timeoutrehashinpyenv initmakes that failure hit every new shellI realize
--no-rehashis a workable user-side fix, but I wanted to add evidence that the.pyenv-shim existsproblem can still translate into a consistent 60-second shell startup delay when the lock file is left behind.If useful, I can provide more details from local testing.
native-api commentedon May 17, 2026
I guess we can assume that a lockfile older than, say, 10 minutes is stale.
We still don't know how this happens but this will at least unblock affected users.
fix(rehash): reduce stale lock TTL to 2 min and add pre-loop sandbox …