Giter Club home page Giter Club logo

Comments (38)

lvh avatar lvh commented on May 18, 2024 44

For posterity: pyenv now supports fish! Try pyenv init in a shell and it will tell you:

# Load pyenv automatically by adding
# the following to ~/.config/fish/config.fish:

status --is-interactive; and . (pyenv init -|psub)

from pyenv.

Eduard-gan avatar Eduard-gan commented on May 18, 2024 25

There's no need to use abandoned fisher plugin.

all you need is to paste this in your ~/.config/fish/config.fish :

set -x PYENV_ROOT $HOME/.pyenv
set -x PATH $PYENV_ROOT/bin $PATH
status --is-interactive; and . (pyenv init -|psub)
status --is-interactive; and . (pyenv virtualenv-init -|psub)

If you're pasting one line mentioned above:
status --is-interactive; and . (pyenv init -|psub)
you'll got the error:

~/.config/fish/config.fish (line 1): pyenv init -|psub
^
in command substitution
called on line -1 of file ~/.config/fish/config.fish

from sourcing file ~/.config/fish/config.fish
called during startup

source: '.' command is deprecated, and doesn't work with STDIN anymore. Did you mean 'source' or './'?

because setting of PYENV_ROOT and PATH enviroment variables before the line which mentions pyenv is crucial!

from pyenv.

 avatar commented on May 18, 2024 22

@yyuu pyenv is awesome, thanks.

Also for posterity, I thought I'd write up a small guide about what's happening here:

status --is-interactive; and . (pyenv init - | psub)

First, status --is-interactive sets the exit $status code to 0 (true) if the terminal is interactive.

As for the -, at least in Unix parlance, - means standard input, but pyenv uses it instead as a silent flag to skip printing a help message that explains how to add pyenv to your profile AFIK.

Now, psub is used for process substitution. Let me explain this via an example, say you want to diff two files:

diff file1 file2

but rather use a string like:

echo $string | diff file1 -

and with two strings:

diff (echo $s1 | psub) (echo $s2 | psub)

and translated to bash:

diff <($s1) <($s2)

In . (pyenv init - | psub), ``.' (a wrapper around the source` builtin) will receive whatever comes out of `pyenv init -` as input.

. evaluates (parses) the output produced by pyenv init..., which is different from spawning a new process and running the output.

⚠️ . is deprecated, please use source from now :)

This, among other things, creates the directories at $PYENV_ROOT/shims, $PYENV_ROOT/versions and sets up pyenv environment.

from pyenv.

fjarri avatar fjarri commented on May 18, 2024 19

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).

from pyenv.

yyuu avatar yyuu commented on May 18, 2024 12

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

from pyenv.

yyuu avatar yyuu commented on May 18, 2024 11

@tiagofernandez
Oops. You're right. The initialization code has been changed during exporting this feature to rbenv (rbenv/rbenv#434).

Now I'm using following initialization code.

set -x PATH "$HOME/.pyenv/bin" $PATH
. (pyenv init - | psub)

from pyenv.

ezdac avatar ezdac commented on May 18, 2024 7

This doesn't work anymore in fish 3.1.0:

status --is-interactive; and . (pyenv init -|psub)
status --is-interactive; and . (pyenv virtualenv-init -|psub)

And can be replaced until the issue is resolved (and it will work after that as well) with this in ~/.config/fish/config.fish:

status --is-interactive; and pyenv init - | source
status --is-interactive; and pyenv virtualenv-init - | source

As of this issue comment:
fish-shell/fish-shell#6613 (comment)

from pyenv.

joshfriend avatar joshfriend commented on May 18, 2024 6

The readme has already been updated to suggest source instead of psub for fish users.

from pyenv.

halfnhalf avatar halfnhalf commented on May 18, 2024 2

Sorry, yes fisher is alive but what I meant was the pyenv fisher package is abandoned
https://github.com/fisherman/pyenv

from pyenv.

tiagofernandez avatar tiagofernandez commented on May 18, 2024 1

I guess the initialization code for Fish is currently . (pyenv init -|psub), right?
Since eval (pyenv init - fish) returns pyenv: no such command sh-'.

from pyenv.

 avatar commented on May 18, 2024 1

@sooheon Hmm. Can you post the error?

You are using the fisherman plugin right?

from pyenv.

 avatar commented on May 18, 2024 1

If you run into other issues, please create an issue in the plugin's repo, fisherman's issue tracker or just contact me directly. Happy fishing! :)

from pyenv.

yyuu avatar yyuu commented on May 18, 2024

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

from pyenv.

fjarri avatar fjarri commented on May 18, 2024

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?

from pyenv.

yyuu avatar yyuu commented on May 18, 2024

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

from pyenv.

yyuu avatar yyuu commented on May 18, 2024

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.

from pyenv.

fjarri avatar fjarri commented on May 18, 2024

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

from pyenv.

yyuu avatar yyuu commented on May 18, 2024

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

Updating Wiki about tips with fish is welcome :)

from pyenv.

fjarri avatar fjarri commented on May 18, 2024

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.

from pyenv.

yyuu avatar yyuu commented on May 18, 2024

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.

from pyenv.

yyuu avatar yyuu commented on May 18, 2024

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

from pyenv.

fjarri avatar fjarri commented on May 18, 2024

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.

from pyenv.

yyuu avatar yyuu commented on May 18, 2024

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 :(

from pyenv.

yyuu avatar yyuu commented on May 18, 2024

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.

from pyenv.

fjarri avatar fjarri commented on May 18, 2024

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.

from pyenv.

fjarri avatar fjarri commented on May 18, 2024

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 :)

from pyenv.

yyuu avatar yyuu commented on May 18, 2024

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

from pyenv.

yyuu avatar yyuu commented on May 18, 2024

@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)

from pyenv.

fjarri avatar fjarri commented on May 18, 2024

Yep, everything seems to work, thank you!

from pyenv.

yyuu avatar yyuu commented on May 18, 2024

ok. I'll merge it into master :)

from pyenv.

aviddiviner avatar aviddiviner commented on May 18, 2024

@bucaran: Thanks for that awesome explanation! Taught me about how psub works.. cool!

from pyenv.

sooheon avatar sooheon commented on May 18, 2024

@BRJ with a recent version of fish, I'm getting source: '.' command is deprecated, and doesn't work with STDIN anymore. Did you mean 'source' or './'? What is the form of this incantation without using ., but source directly?

from pyenv.

 avatar commented on May 18, 2024

@sooheon Yes, use source please.

. is history now :)

from pyenv.

sooheon avatar sooheon commented on May 18, 2024

Sorry but my question was just about the syntax of how to do that--directly replacing . with source gives an error.

from pyenv.

sooheon avatar sooheon commented on May 18, 2024

I am now :). I had just copy pasted the snippet above in my fish.config before. Thanks.

from pyenv.

halfnhalf avatar halfnhalf commented on May 18, 2024

Looks like fisherman is abandoned. Any new alternatives?

from pyenv.

 avatar commented on May 18, 2024

Updates ?

from pyenv.

sdouche avatar sdouche commented on May 18, 2024

Fisher is alive: https://github.com/jorgebucaran/fisher

from pyenv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.