Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use powerline with pyenv-virtualenv? #358

Closed
anentropic opened this issue Feb 7, 2018 · 14 comments
Closed

How to use powerline with pyenv-virtualenv? #358

anentropic opened this issue Feb 7, 2018 · 14 comments

Comments

@anentropic
Copy link

I upgraded from something very old to recent powerline

But now when I do pyenv activate myenv my prompt dies because powerline is not installed in the virtualenv

Is there a workaround for this?

@anentropic
Copy link
Author

(I mean apart from installing it in all my virtualenvs, which I've been doing in the meantime and works but is a bit of a pain)

@b-ryan
Copy link
Owner

b-ryan commented Feb 7, 2018

Admittedly I haven't worked with pyenv. So I'm going to have to learn about it a bit.

So you used pip to install the project, correct? And what is the exact error you are getting?

@anentropic
Copy link
Author

~ > Documents > etc > $ pyenv activate myenv
pyenv: powerline-shell: command not found

The `powerline-shell' command exists in these Python versions:
  2.7.11

powerline-shell is installed in my system python (2.7.11) via pip

I can pip install it into the current pyenv-virtualenv and my bash prompt works again

Maybe I can add something in my .bashrc to run powerline-shell with a specific python version and packages dir

@b-ryan
Copy link
Owner

b-ryan commented Feb 24, 2018

I am not able to reproduce this issue. Could you perhaps provide all the commands necessary to reproduce? I uninstalled powerline-shell and then did the following:

sudo pip install powerline-shell
pyenv virtualenv -p $(which python3) test-env
pyenv activate test-env

@MaxyBlack
Copy link

I've had similar issue, solved it with this code

if [ "$TERM" != "linux" ]; then if type "powerline-shell" &> /dev/null; then PROMPT_COMMAND="_update_ps1; $PROMPT_COMMAND" fi fi

@jaymzcd
Copy link

jaymzcd commented Apr 26, 2018

I had the exact same behavior as @anentropic (Hi Paul! Cracks me up every time I google an issue like this you've already posted an SO answer or GH issue 😂).

After starting to use PyEnv myself on a new mac that I setup with powerline. @b-ryan's comment gave me an idea. I had installed powerline using the pyenv installed python and so there was a shim present at ~/.pyenv/shims/powerline. I removed the pyenv version and installed system wide using sudo which placed it in /usr/local/bin/powerline.

When I then activated my (pyenv) environment I no longer got the error. I believe it's because pyenv places it's shim folder in front of your $PATH and then since you are in a new environment with the shim references having priority but no powerline in the env you end up with the "command not found" error.

Try removing powerline from the pyenv and installing it system wide first before activating.

@anentropic
Copy link
Author

Hi @jaymzcd ! I haven't tried this yet but it sounds promising!

@b-ryan
Copy link
Owner

b-ryan commented May 2, 2018

@jaymzcd that makes sense. I wonder if the straightforward solution is to install with the system pip:

sudo /usr/bin/pip install powerline-shell

@anentropic
Copy link
Author

yes this totally worked for me

deleted the pyenv shim version, then sudo /usr/local/bin/pip install powerline-shell

👍

@b-ryan
Copy link
Owner

b-ryan commented May 17, 2018

Excellent! I will put this in the FAQ.

@b-ryan b-ryan closed this as completed May 17, 2018
@anentropic
Copy link
Author

Unfortunately for some reason the shim is recreated every time the pyenv virtualenv is activated (also whenever you pip install/uninstall with the venv activated)

I have not found a permanent solution yet

see pyenv/pyenv#1112

@deanishe
Copy link

@anentropic pyenv-which-ext should prevent pyenv shims giving you "command not found" errors when the shadowed program is installed on the system.

@cmburg
Copy link

cmburg commented Nov 27, 2019

@jaymzcd that makes sense. I wonder if the straightforward solution is to install with the system pip:

sudo /usr/bin/pip install powerline-shell

I had to extend this commad with the -H-option, since I got an error message with conflicting permissions.

@SiggyF
Copy link

SiggyF commented Apr 10, 2020

You can also install commands that should be available outside venvs using pipx.

pipx install powerline-shell

Make sure that your PATH contains ~/.local/bin, for example like this in your .profile
export PATH=~/.local/bin:$PATH

This results in a new virtualenv created by pipx specifically for powerline-shell. It will also install a link this powerline-shell cli in ~/.local/bin so that you can use it from anywhere, also outside the venv it creates. This way you can install powerline-shell in your home folder and use it inside
different venvs without needing sudo rights.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants