11

Regarding pyenv: https://github.com/pyenv/pyenv

I have this:

$ pyenv global 2.7
$ python --version
Python 3.6.4

My pyenv version is:

pyenv 1.2.2

does anyone know the right way to set a python version for any particular shell (and child shells)?

4
  • If I am not very mistaken you can just do pyenv shell X.X Commented Apr 30, 2018 at 21:59
  • @patrick, I get pyenv: no such command shell'` Commented Apr 30, 2018 at 22:00
  • According to the docs the shell command should be a thing. But note Note that you'll need pyenv's shell integration enabled (step 3 of the installation instructions) in order to use this command. Looks like that just requires adding pyenv init to your shell Commented Apr 30, 2018 at 22:06
  • Can you post the output of the command echo $PATH? Commented May 1, 2018 at 13:44

2 Answers 2

10

Just to elaborate on my comment, now that I have some time.

The docs describe the shell command for this purpose, which you can run like so:

pyenv shell pypy-2.2.1

Notes:

If you installed pyenv via Homebrew et al, that should work out of the box (it did for me). If not, the installation instructions detail a necessary step:

Add pyenv init to your shell to enable shims and autocompletion. Please make sure eval "$(pyenv init -)" is placed toward the end of the shell configuration file since it manipulates PATH during the initialization.

The specific command they suggest (for bash) is:

$ echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bash_profile

Then restart the shell.

There is some further caveats for specific shells listed on the installation instructions linked. Hope this helps.

Sign up to request clarification or add additional context in comments.

1 Comment

for zsh can we change .bash_profile to zsh_profile or zshrc ? any more changes needed here ?
-2

For MacOS I had to set the global version pyenv global 3.10.1 and then exec $SHELL

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.