prezto: Python module failing to run pyenv virtualenv-init

Description

It seems like the Python module is incorrectly using the commands array, by trying to find a command named pyenv-virtualenv-init, causing the module to not find and run pyenv virtualenv-init. Line in question: https://github.com/sorin-ionescu/prezto/blob/master/modules/python/init.zsh#L96

But looking at the code history, the Python module has been using this since April of 2017 1050a0a290324f3b96256d3b1fefe4a84ab402d0, so I feel like I must be doing something wrong.

I have pyenv installed with the virtualenv plugin, but when I run $+commands[pyenv-virtualenv-init] in my shell I get 0

Expected behavior

virtualenv is loaded via pyenv

Actual behavior

virtualenv is not loaded, and an error is printed on shell open

/home/zwhaley/.zprezto/modules/python/init.zsh:source:109: no such file or directory: 

Steps to Reproduce

  1. Enable Python module zstyle ':prezto:module:python:virtualenv' auto-switch 'yes'
  2. Open shell

Versions

  • Prezto commit: dbf96d2d3749b2905927a08c55a8c9eba12c8425
  • ZSH version: zsh 5.3.1 (x86_64-redhat-linux-gnu)
  • OS information: Fedora release 26 (Twenty Six) x86_64

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 16 (14 by maintainers)

Most upvoted comments

@indrajitr The reason it worked for me is because I was on a Mac and installed the pyenv-virtualenv package from Homebrew. This package places an executable pyenv-virtualenv-init in /usr/local/bin, which is on the user’s path, so the $+commands[pyenv-virtualenv-init] returns true.

However, when installing pyenv-virtualenv on Ubuntu using either the pyenv-installer or simply Git cloning into ~/.pyenv/plugins, there is no pyenv-virtualenv-init on the path. @zachwhaley’s grep solution works in either case, so I think that is the way to go.

Edit: There does seem to be some confusion here regarding the difference between pyenv-virtualenv-init and pyenv virtualenv-init. One has a dash, the other a space. The former is what prezto is currently checking for on the path, while the latter is the actual command to be executed.

If you want to avoid calling a command that doesn’t exist, you could use the pyenv commands command to list the available commands and grep for virtualenv-init

e.g.

if pyenv commands | command grep -q virtualenv-init; then
    $(pyenv virtualenv-init -)
fi