Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set default python with pyenv

I am try to upgrade my Python version on my macOS Catalina 10.15.1 by install PYENV and PYPIP, and set global and local to version 3.8.0. but still when I try to python version it shows the python version which built into the MacOS operating system. which part is missing?

$ pyenv -v
pyenv 1.2.14

$ pypip -v
zsh: command not found: pypip

$ pyenv versions
  system
* 3.8.0 (set by /Users/aj/.python-version)

$ pyenv global
3.8.0

$ pyenv local
3.8.0

$ python -V
Python 2.7.16
like image 808
AJ- Avatar asked Nov 03 '19 11:11

AJ-


2 Answers

For me OSX I had to put

eval "$(pyenv init --path)"

inside my ~/.bashrc | ~/.zshrc

note that without the --path it didn't work

like image 131
Oded BD Avatar answered Sep 18 '22 14:09

Oded BD


If the output of

type -a python 

is /usr/bin/python, and if there is no second line displayed, then pyenv is only setup partially.

You should have seem as first line something like

/home/username/.pyenv/shims/python

That means your pyenv is not setup properly. It is only set up partially. What's missing is the pyenv shims which redirect to the correct version of python.

Probably your search path contains: /home/username/.pyenv/bin, but it is missing /home/username/.pyenv/shims

(Following comments updated 2021-01-06):

Normally you should have three lines in your ~/.bashrc

The first two (or something equivalent), that you seem to have are:

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile

On the other hand what you seem to be missing is a line, that looks like:

echo 'eval "$(pyenv init -)"' >> ~/.bash_profile

or a more elaborate but in most cases identical line:

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

Try to add one of these missing lines to your .bashrc and see whether pyenv is working better.

You could also add ~/.pyenv/shims/python manually to your searchpath, but normally this should have been done by the eval "$(pyenv init -)" command

if ~/.pyenv/shims is already in your search path, then check with

ls ~/.pyenv/shims

whether the directory exists and contains an executable named python. Normally this should have been added latest after having done a pyenv install 3.8.0

Addendum 2022-01-15:

Please note that the way pyenv is initialized changed. If you had an older pyenv version and you updated the cloned repository you have probably something like

eval "$(pyenv init -)"

in your ~/.bash_profile

This has to be changed to something lile

eval "$(pyenv init -)"
eval "$(pyenv init --path)"
like image 35
gelonida Avatar answered Sep 16 '22 14:09

gelonida