Pyenv not auto activating
Asked Answered
V

1

10

I have pyenv installed in my environment and up to this weekend (when I installed 'Kivy') my pyenv/local setup has been working fine. But now when I go to my various python project directories, pyenv does not automatically activate the right python version properly.

E.g.

I create an environment using pyenv like this,

pyenv virtualenv 3.3.2 work

I make and go into a dir called work and have a .python-version file with the text work as the sole content.

Pyenv detects that my environment is work using this file but my python version is not python 3.3.2 instead it's 2.7.9.

For some reason, something happened, and all of my pyenv virtual environments use 2.7.9 as opposed to the python version they were created with.

When I run which python I get,

/opt/boxen/homebrew/bin/python

when I go to the pyenv version directory and run

$ cat pyvenv.cfg                                                                                                                                                                                           
home = /opt/boxen/pyenv/versions/3.3.2/bin
include-system-site-packages = false 
version = 3.3.2

However, if I run pyenv activate I my python version switches to python 3.3.2 (or the appropriate version for a given env).

Question is, how do I get pyenv to auto activate the environment's python version as it did before (before I did something to break it).

Vinia answered 16/2, 2015 at 15:27 Comment(0)
M
15

It sounds like, because of which python not saying it's the shim, you don't have the bin/shims path first in your PATH envvar. Add these lines to your shell startup script, and make sure they're at the end, after any other path manipulations.

export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"

The eval line does some additional shell monkeying I think to add the .pyenv/shims directory...check that with an echo $PATH maybe.

Multiplex answered 16/2, 2015 at 21:53 Comment(6)
Thanks but pyenv is in my path, here's my path, export PATH="/Users/me/.autojump/bin:bin:/opt/boxen/rbenv/shims:/opt/boxen/rbenv/bin:/opt/boxen/rbenv/plugins/ruby-build/bin:/opt/boxen/pyenv/shims:/opt/boxen/pyenv/bin:node_modules/.bin:/opt/boxen/nodenv/shims:/opt/boxen/nodenv/bin:/opt/boxen/bin:/opt/boxen/homebrew/bin:/opt/boxen/homebrew/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/git/bin"Vinia
That's my path from my zsh startup scriptVinia
@user does anything else modify it (check in an actual shell instead of looking at the script)?Multiplex
Nothing modifies it, when i run echo $PATH /Users/me/.pyenv/bin:/Users/ahmed/.autojump/bin:bin:/opt/boxen/rbenv/shims:/opt/boxen/rbenv/bin:/opt/boxen/ruby-build/bin:/opt/boxen/pyenv/bin:node_modules/.bin:/opt/boxen/nodenv/shims:/opt/boxen/nodenv/bin:/opt/boxen/bin:/opt/boxen/homebrew/bin:/opt/boxen/homebrew/sbin:/Users/ahmed/.autojump/bin:bin:/opt/boxen/rbenv/shims:/opt/boxen/rbenv/bin:/opt/boxen/rbenv/plugins/ruby-build/bin:/opt/boxen/pyenv/shims:/opt/boxen/pyenv/bin:node_modules/.bin:/opt/boxen/nodenv/shims:/opt/boxen/nodenv/bin:/opt/boxen/bin:/opt/boxen/homebrew/bin:...Vinia
It seems like my initial guess was correct /opt/boxen/pyenv/‌​shims is not the first (or first among places that have python, pip, etc. in it), because it's after /opt/boxen/homebrew‌​/bin, which which python is telling you it's using.Multiplex
Thanks! I've gotten things straightened away now. Although I never altered anything, I wonder why this has occurred... :/Vinia

© 2022 - 2024 — McMap. All rights reserved.