justinmayer / virtualfish

Fish shell tool for managing Python virtual environments

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to specify minor python version when using pyenv?

morberg opened this issue · comments

  • I am using Fish shell version 3.1 or higher.
  • I am using Python version 3.6 or higher.
  • I have searched the issues (including closed ones) and believe that this is not a duplicate.
  • OS version and name: macOS 11.1
  • Fish shell version: 3.1.2
  • VirtualFish version: 2.5.1

Issue

How do I specify e.g. python 3.8.6 when using pyenv? I can only get 3.8.0 or 3.9.0 to work.

❯ pyenv versions
  system
  3.8.0
* 3.8.6 (set by /Users/niklas/.pyenv/version)
  3.9.0

~
❯ python --version
Python 3.8.6

~
❯ vf new 386
Creating 386 via ~/.pyenv/versions/3.8.0/bin/python …

~
386 ❯ python --version
Python 3.8.0

I thought the current python would be used for a new virtualenv, but it seems the version used when I pip installed virtualfish is used.

If I try to specify the python version the command is not found:

❯ vf new -p python3.8.6 386
pyenv: python3.8.6: command not found
Creating 386 via python3.8.6 …
RuntimeError: failed to find interpreter for Builtin discover of python_spec='python3.8.6'
Error: The virtual environment was not created properly.
Virtualenv returned status 1.

Omitting the .6 works, but gives me 3.8.0 and not 3.8.6 (which is probably reasonable).

~
❯ vf new -p python3.8 380
Creating 380 via ~/.pyenv/shims/python3.8 …

~

Creating a version with 3.9.0 works (but probably not 3.9.1):

~
❯ vf new -p python3.9 390
Creating 390 via python3.9 …

~
390 ❯ python --version
Python 3.9.0

What made you think 386 or 390 would work? Oh, I see, you are using those as virtual environment names.

You are getting that error because Python does not create separate executables for patch-level Python versions, which is why you do not have python3.8.6 on your PATH, which is why VirtualFish cannot find what you specified. Instead, choose from among the following alternate invocations, in order of reliability:

vf new -p ~/.pyenv/versions/3.8.6/bin/python foo  # Full path is most reliable
vf new -p $(pyenv which python 3.8.6) foo  # Or something like that; I don't use Pyenv
vf new -p 3.8.6 foo  # Most convenient but vague if multiple 3.8.6 interpreters exist

Thank you. I could only get your first line to to work.

I couldn't figure out how to get pyenv to point me to 3.8.6 in your second suggestion, probably because there is no executable/shim for that version.

It would be nice to use the third one, but it fails in the same way as specifying python3.8.6

❯ vf new -p 3.8.6 foo 
pyenv: python3.8.6: command not found
Creating foo via 3.8.6 …
RuntimeError: failed to find interpreter for Builtin discover of python_spec='3.8.6'
Error: The virtual environment was not created properly.
Virtualenv returned status 1.

What do you recommend instead of pyenv? I certainly don't have to use that to manage python versions if there are alternatives that work better.

Hi @morberg. Very sorry for the long delay in responding. I use asdf with the asdf-python plugin. If you skip past a long unrelated rant about Homebrew, you can find the steps I used to set it up.

Regarding the version resolution issue described here, I'll merge the solution @cecep2 contributed shortly.