pyenv icon indicating copy to clipboard operation
pyenv copied to clipboard

Fish shell support

Open fjarri opened this issue 13 years ago • 38 comments

Is the support of fish shell planned? There are some mentions of fish on wiki, but currently pyenv does not work in it.

Namely, the problem is pyenv init, which tries to perform a bash eval inside fish, which, of course, fails. Installation/uninstallation of Python versions seems to work normally.

fjarri avatar Jul 15 '13 01:07 fjarri

I'd like to support even for fish if it is available, but it seems somewhat difficult with current impl :(

Many of the code of pyenv is written in bash, but there are some of interactions between working shell. They might be the problem to support fish.

  1. pyenv init
    • need to prepare shell-specific init script
  2. pyenv shell
    • export is not workable on fish
  3. auto-completion
    • need shell-specific code

yyuu avatar Jul 15 '13 14:07 yyuu

I'd personally be happy if init worked, I don't really use 2 or 3. Do I understand it correctly that the primary function of init is to call rehash and add stuff to PATH, and that's what makes global/local work?

fjarri avatar Jul 15 '13 14:07 fjarri

Yep, you're right. The global and local can work without init.

yyuu avatar Jul 16 '13 03:07 yyuu

Adding following snippet in your shell initialization script (something like ~/.profile of sh for fish) might help you.

setenv PYENV_ROOT "${HOME}/.pyenv"
setenv PATH "${PYENV_ROOT}/shims:${PYENV_ROOT}/bin:${PATH}"
pyenv rehash

yyuu avatar Jul 16 '13 03:07 yyuu

Thank you for the suggestion! In fish syntax it seems to be

set PYENV_ROOT $HOME/.pyenv
set -x PATH $PYENV_ROOT/shims $PYENV_ROOT/bin $PATH
pyenv rehash

The only problem is that modules that install stuff in bin do not work properly. For example, if I install yolk (a tool that generates a list of available modules), pip correctly installs it in ~/.pyenv/versions/2.7.5/lib/python2.7/site-packages/, and puts yolk executable in ~/.pyenv/versions/2.7.5/bin/, but when I call yolk from the command line, it results in the call to /usr/local/bin/yolk (the system one).

fjarri avatar Jul 16 '13 03:07 fjarri

You might need pyenv rehash to generate shim for yolk after installing pip install yolk. Plus, you might need to invoke something like rehash (zsh) or hash -r (bash) to update command table of the current shell.

yyuu avatar Jul 16 '13 06:07 yyuu

Oh, it seems that I did not quite understand what pyenv rehash does. Thank you, that did help, no additional shell commands were necessary.

fjarri avatar Jul 16 '13 06:07 fjarri

Is there any other problem? Or, I wanna close this.

Updating Wiki about tips with fish is welcome :)

yyuu avatar Jul 19 '13 13:07 yyuu

Well, there's still an issue of shell and auto-completion, which may be important for some people. Plus there are some weird problems of pip running 2to3 when I install packages for Py2 and not running it when I install packages for Py3, which does not happen when I install them from their source directory (I cannot pinpoint the cause of this yet).

Basically, what I'm saying is, the issue of me using pyenv with fish is somewhat resolved, but the issue of pyenv supporting fish is not, so use your best judgement :) I will update the wiki as soon as I resolve the pip problem.

fjarri avatar Jul 19 '13 13:07 fjarri

My decision on this is, pyenv should even work on non-sh-style shells (like fish and csh), but init, shell and auto-completion are limited on these shells.

Supporting full features on non-sh-style shells is very hard and will not be implemented. This does not mean it is impossible; it is possible if I wrote scripts like libexec/pyenv-init.fish and completions/pyenv.fish and some more. But I will not implement them because I am not an expert of these shells. (patches are welcome!)

Even if the support is limited, most of the features (like local, global and install) are still available. I think this means pyenv is still useful for the users of non-sh-style shells.

yyuu avatar Jul 19 '13 23:07 yyuu

Please describe more about the weird problems of pip running 2to3.

  1. Which python version did you use with?
  2. What is the package did you try to pip install?
  3. Please paste the error output from pip

yyuu avatar Jul 19 '13 23:07 yyuu

For example:

~> pyenv global 2.7.5
~> pyenv rehash
~> pip install decorator -v
Downloading/unpacking decorator
  Running setup.py egg_info for package decorator
    running egg_info
    writing pip-egg-info/decorator.egg-info/PKG-INFO
    writing top-level names to pip-egg-info/decorator.egg-info/top_level.txt
    writing dependency_links to pip-egg-info/decorator.egg-info/dependency_links.txt
    warning: manifest_maker: standard file '-c' not found

    reading manifest file 'pip-egg-info/decorator.egg-info/SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    warning: no files found matching 'documentation.py'
    warning: no files found matching 'documentation3.py'
    warning: no previously-included files found matching 'Makefile'
    writing manifest file 'pip-egg-info/decorator.egg-info/SOURCES.txt'
Installing collected packages: decorator
  Running setup.py install for decorator
    running install
    running build
    running build_py
    running install_lib
    copying build/lib/decorator.py -> /Users/bogdan/.pyenv/versions/2.7.5/lib/python2.7/site-packages
    byte-compiling /Users/bogdan/.pyenv/versions/2.7.5/lib/python2.7/site-packages/decorator.py to decorator.pyc
      File "/Users/bogdan/.pyenv/versions/2.7.5/lib/python2.7/site-packages/decorator.py", line 158
        print('Error in generated code:', file=sys.stderr)
                                              ^
    SyntaxError: invalid syntax

    running install_egg_info
    running egg_info
    writing src/decorator.egg-info/PKG-INFO
    writing top-level names to src/decorator.egg-info/top_level.txt
    writing dependency_links to src/decorator.egg-info/dependency_links.txt
    warning: manifest_maker: standard file '-c' not found

    reading manifest file 'src/decorator.egg-info/SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    warning: no files found matching 'documentation.py'
    warning: no files found matching 'documentation3.py'
    warning: no previously-included files found matching 'Makefile'
    writing manifest file 'src/decorator.egg-info/SOURCES.txt'
    Copying src/decorator.egg-info to /Users/bogdan/.pyenv/versions/2.7.5/lib/python2.7/site-packages/decorator-3.4.0-py2.7.egg-info
    running install_scripts
    writing list of installed files to '/var/folders/hq/kzp38x892h7g5nj6rr5p6d7c0000gn/T/pip-tDOBwU-record/install-record.txt'
Successfully installed decorator
Cleaning up...

Note the syntax error. If you look into https://pypi.python.org/packages/source/d/decorator/decorator-3.4.0.tar.gz you'll see a Py2-style print statement there. If I download the sources, cd there and run pip install ., it installs correctly.

fjarri avatar Jul 20 '13 00:07 fjarri

Couldn't confirm this weird behaviour.

I think that there is something wrong in distutils or setuptools. The setup.py running on 2.7.5 should not invoke 2to3 because the distutils of 2.7.5 lacks distutils.util.Mixin2to3. Setting the Python's environment variables of PYTHONHOME or PYTHONPATH might introduce this kind of confusion. But I'm not sure what is happening there :(

yyuu avatar Jul 20 '13 16:07 yyuu

I heard similar weird behaviour of 2to3 in #38. In that case, upgrading setuptools from 0.7.2 to 0.9.7 (latest) solves the problem.

yyuu avatar Jul 23 '13 15:07 yyuu

Upgrading setuptools did not work for me, unfortunately. I have also found some other mentions of this problem (e.g. http://code.google.com/p/sympy/issues/detail?id=3437), and it seems that it is probably something related to pip and not pyenv. I'll close this for now, since this issue is quite elusive.

fjarri avatar Jul 23 '13 15:07 fjarri

Just for the sake of closure: the problem has been resolved by updating pip from 1.3.1 to 1.4. Sorry for blaming pyenv :)

fjarri avatar Jul 24 '13 01:07 fjarri

I noticed the update of pip by your mention here. Thanks for your comment :)

yyuu avatar Jul 24 '13 06:07 yyuu

@Manticore I wrote some additional scripts to improve fish support of pyenv. The init, shell and completions are now working on fish. Please try fish-support branch at pyenv repo.

https://github.com/yyuu/pyenv/tree/fish-support

Initialization code for fish.

setenv PATH "$HOME/.pyenv/bin" $PATH
eval (pyenv init - fish)

yyuu avatar Aug 15 '13 14:08 yyuu

Yep, everything seems to work, thank you!

fjarri avatar Aug 16 '13 01:08 fjarri

ok. I'll merge it into master :)

yyuu avatar Aug 16 '13 03:08 yyuu