python-launcher: pyenv 'command not found' with system python set

Describe the bug Encountering error running py due to pyenv installed and set to system

$ py
pyenv: python3.9: command not found

The `python3.9' command exists in these Python versions:
  3.9.2

Note: See 'pyenv help global' for tips on allowing both
      python2 and python3 to be found.

To Reproduce

  1. Install pyenv
  2. pyenv install 3.9.2
  3. cargo install python-launcher
  4. py

Tried export PY_PYTHON as per FAQ but version file does not exist if global not set:

head: cannot open '~/.pyenv/version' for reading: No such file or directory

So tried creating file with pyenv global but that also failed on the special string system:

Error parsing 'system' as an integer: invalid digit found in string

Expected behaviour Opens system python 3.8 prompt

Screenshots

$ pyenv versions
* system (set by ~/.pyenv/version)
  3.9.2
$ py --list
 3.9 │ ~/.pyenv/shims/python3.9 
 3.8 │ /usr/bin/python3.8                 
 3.6 │ /usr/bin/python3.6                 
 2.7 │ /usr/bin/python2.7 

System Details (please complete the following information):

  • OS: Ubuntu 20.04
  • Shell: bash
  • Launcher Version: 1.0.0

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (13 by maintainers)

Commits related to this issue

Most upvoted comments

It works for all combinations however for completeness need to include PY_PYTHON3 for py -3 command:

export PY_PYTHON=$(pyenv exec python -c "import sys; print('.'.join(map(str, sys.version_info[0:2])))") 
export PY_PYTHON3=$(pyenv exec python3 -c "import sys; print(*sys.version_info[0:2], sep='.')") 

* Didn’t use print sep arg for python just in-case python2 is being used.

The final issue to note is that once env vars are set any changes to pyenv global will not update them until session reload. Could be fixed with alias for py prefixed with env vars set at runtime but might be overkill.

Maybe the best-effort here is to check for PYENV_ROOT and exclude any paths prefixed by that?

That’s still pyenv-specific and so I would rather not do that.

After considering all of this I can understand if you instead want to say that launcher is not compatible with pyenv.

I don’t want to go that far as people like @jefftriplett have shown they get use out of the Launcher with pyenv (as has @treyhunner and other folks who helped write that FAQ entry). Maybe they can share how they make them work together?

Then when creating a new git project, I always start with running e.g. “pyenv local 3.9.6” which creates a .python_version file.

Then the Launcher isn’t necessarily that useful. It still helps with shebangs and using the newest version of Python and using virtual environments automatically. But if you’re already using pyenv to accomplish this then you don’t need the Launcher (or you can obviously switch over if you want 😉).

Otherwise we can add a disclaimer to the FAQ entry to say system is not a supported version (or both; simple sample or more complex sample depending on what people want).