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

Trouble Switching Python Versions #185

Closed
jackmaney opened this issue Jun 4, 2014 · 14 comments
Closed

Trouble Switching Python Versions #185

jackmaney opened this issue Jun 4, 2014 · 14 comments

Comments

@jackmaney
Copy link
Contributor

I'm using OSX Mavericks (10.9.3) on pyenv version 0.4.0-20140602. I'm finding that pyenv rarely switches installed versions of python. Somehow, I got pyenv to switch from the system python to 2.7.7, but I can't switch it to anything else:

jackmaney@Jacks-Mac-mini:~$ python --version
Python 2.7.7
jackmaney@Jacks-Mac-mini:~$ pyenv versions
  system
* 2.7.7 (set by /Users/jackmaney/.python-version)
  3.4.1

Okay, so far, so good...pyenv recognizes both versions that it installed (2.7.7 and 3.4.1). Let's try to switch to 3.4.1:

jackmaney@Jacks-Mac-mini:~$ pyenv global 3.4.1
jackmaney@Jacks-Mac-mini:~$ python --version
Python 2.7.7
jackmaney@Jacks-Mac-mini:~$ pyenv versions
  system
* 2.7.7 (set by /Users/jackmaney/.python-version)
  3.4.1

No dice... The same thing happens if I try to switch back to the system Python:

jackmaney@Jacks-Mac-mini:~$ pyenv global system
jackmaney@Jacks-Mac-mini:~$ python --version
Python 2.7.7
jackmaney@Jacks-Mac-mini:~$ pyenv versions
  system
* 2.7.7 (set by /Users/jackmaney/.python-version)
  3.4.1

I've set up the eval command and have $PYENV_ROOT set to the correct directory:

jackmaney@Jacks-Mac-mini:~$ echo $PYENV_ROOT
/usr/local/opt/pyenv

Also, both of $PYENV_ROOT/bin and $PYENV_ROOT/shims are in my $PATH.

My apologies if I'm missing something obvious.

@jackmaney
Copy link
Contributor Author

Also, if it helps, I installed pyenv via homebrew.

@yyuu
Copy link
Contributor

yyuu commented Jun 5, 2014

It's depending on the $PATH setting. Please make sure $PYENV_ROOT/shims is in front of /usr/local/bin in the $PATH if you have brew built CPython 2.7.7.

@yyuu yyuu added the question label Jun 5, 2014
@jackmaney
Copy link
Contributor Author

I checked, and $PYENV_ROOT/shims is in front of /usr/local/bin:

jackmaney@Jacks-Mac-mini:~$ echo $PATH
/Users/jackmaney/perl5/perlbrew/bin:/Users/jackmaney/perl5/perlbrew/perls/perl-5.18.2/bin:/usr/local/opt/pyenv/bin:/usr/local/opt/pyenv/shims:/Users/jackmaney/.pyenv/shims:/Library/Frameworks/Mono.framework/Versions/Current/bin:/usr/local/bin:/Users/jackmaney/.cabal/bin:/usr/local/Cellar/go/1.2/libexec/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/texbin:/Users/jackmaney/go/bin

@yyuu
Copy link
Contributor

yyuu commented Jun 5, 2014

hmm... It's strange.

Are you using bash as your shell? Please let me know the output from which python and pyenv which python.

@jackmaney
Copy link
Contributor Author

Yep, bash is my shell.

jackmaney@Jacks-Mac-mini:~$ which python
/usr/local/opt/pyenv/shims/python
jackmaney@Jacks-Mac-mini:~$ pyenv which python
/usr/local/opt/pyenv/versions/2.7.7/bin/python

@yyuu
Copy link
Contributor

yyuu commented Jun 5, 2014

It seems that your installation have some configurations in ~/.pyenv in spite of you have set PYENV_ROOT as /usr/local/opt/pyenv. Try moving ~/.pyenv to somewhere and then restart your shell might help.

@jackmaney
Copy link
Contributor Author

Interesting....after performing rm -rf ~/.pyenv and restarting the shell, ~/.pyenv appears again (along with empty shims and versions subdirectories). My bash-fu isn't super strong, but I'm not immediately seeing anything within $(pyenv init -) that would cause this behavior, and I don't see anything in my .bash_profile that would automatically do this upon each shell start, either.

@jackmaney
Copy link
Contributor Author

I uninstalled pyenv (via homebrew), did a rm -rf ~/.pyenv, restarted the shell, and ~/.pyenv still didn't exist. I then reinstalled pyenv, restarted the shell, and ~/.pyenv was there again...

@yyuu
Copy link
Contributor

yyuu commented Jun 5, 2014

If there is PYENV_ROOT defined as an environment variable, pyenv will respect the value as its root directory. https://github.com/yyuu/pyenv/blob/6efe6dafe774d84859d5e5336929e45f0bb3403d/libexec/pyenv#L41

I confirmed that it is working expectedly with my brew installed pyenv v0.4.0-20140602. I have no idea why your pyenv works so strange...

% brew uninstall pyenv
Uninstalling /usr/local/Cellar/pyenv/20140602...
% brew install pyenv
==> Downloading https://github.com/yyuu/pyenv/archive/v0.4.0-20140602.tar.gz
Already downloaded: /Library/Caches/Homebrew/pyenv-20140602.tar.gz
==> Caveats
To enable shims and autocompletion add to your profile:
  if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi

To use Homebrew's directories rather than ~/.pyenv add to your profile:
  export PYENV_ROOT=/usr/local/opt/pyenv
==> Summary
🍺  /usr/local/Cellar/pyenv/20140602: 274 files, 2.5M, built in 2 seconds
% ls ~/.pyenv
ls: /Users/yyuu/.pyenv: No such file or directory
% exec "$SHELL"
% ls ~/.pyenv
ls: /Users/yyuu/.pyenv: No such file or directory
% which pyenv
/usr/local/bin/pyenv
% export PYENV_ROOT=/usr/local/opt/pyenv
% eval "$(pyenv init -)"
% pyenv versions
* system (set by /usr/local/opt/pyenv/version)

@jackmaney
Copy link
Contributor Author

Thankfully, wiping the Python installs allowed pyenv to switch to the system install, but after reinstalling 2.7.7, I can't globally switch to it.

I've uninstalled and reinstalled pyenv multiple times. I've manually wiped the directories where pyenv does its Python installs. I've even switched $PYENV_ROOT to $HOME/.pyenv.

Now, here's the interesting thing...I can do a local switch (pyenv local 2.7.7). I also reinstalled 3.4.1 via pyenv and I can do a local switch to that, as well. However, global switches are still being ignored.

@mattjmorrison
Copy link

I was having the same issues - I was able to get pyenv local working by adding the following to my .zshrc file (if you're not using zsh then add the following to your .bashrc file)

export PYENV_ROOT=~/.pyenv
export PATH=$PYENV_ROOT/shims:$PATH

pyenv global does not seem to work for me either (also - unrelated by pyenv shell does not seem to exist)

@llazzaro
Copy link

llazzaro commented Oct 6, 2014

Hello,

I also had the same problems with fedora. I think virtualenv or virtualenvwrapper caused this problems in my setup.

@yyuu
Copy link
Contributor

yyuu commented Oct 9, 2014

@llazzaro Probably, you are right.The ./bin/activate script of virtualenv might affect the $PATH.

Close this issue because this is out of date. Anyway, please be careful what your $PATH is pointing.

@fphilipe
Copy link

fphilipe commented Aug 5, 2015

Just ran into this issue. I followed the installation instruction from brew info pyenv:

To enable shims and autocompletion add to your profile:
  if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi

To use Homebrew's directories rather than ~/.pyenv add to your profile:
  export PYENV_ROOT=/usr/local/var/pyenv

So I had the export after the if, which caused it to not work. Having the export before the pyenv initialization fixes it and, in hindsight, is obvious that the var should be set before. It might be a good idea to update the installation instruction on the homebrew package to say:

To use Homebrew's directories rather than ~/.pyenv add to your profile before the line above:

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

No branches or pull requests

5 participants