5

I have MacOS Catalina and I went ahead and did a brew install for the latest version of python 3.8.5. Then I discovered pyenv and installed that as well. I followed the steps on https://github.com/pyenv/pyenv#basic-github-checkout from number 3 but still can't see any python versions in pyenv.

I have both .zprofile and .zshrc files and am wondering if that's causing issues. Here's my echo $PATH -

/Users/pq0252/.pyenv/shims/shims:/Users/pq0252/.pyenv/shims/shims:/Users/pq0252/.pyenv/shims:/Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin 

Here's the pyenv version output:

pyenv versions
* system (set by /Users/pq0252/.pyenv/shims/version) 

Here's the .zprofile contents -

 #Setting PATH for Python 3.8.   
 #The original version is saved in .zprofile.pysave.   
PATH="/Library/Frameworks/Python.framework/Versions/3.8/bin:${PATH}"   
export PATH 

Here's the .zshrc contents (this seems to be repeating the if condition, even though I only added it once which I am thinking has something to do with the step 3 on pyenv github where we are appending to it?).

export PYENV_ROOT="$HOME/.pyenv/shims"
export PATH="$PYENV_ROOT:$PATH"
export PIPENV_PYTHON="$PYENV_ROOT/python"
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\n$
if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init -)"
fi
if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init -)"
fi

Should I remove entries in .zshrc and instead add everything to .zprofile or is there something else I'm missing? python3 --version does show 3.8.5.

linuxNoob
  • 600
  • 2
  • 14
  • 30

1 Answers1

3

Here's what I see when I run pyenv versions

➜  ~ pyenv versions
* system (set by /Users/gwanghyeongim/.pyenv/version)
  3.7.6
  3.7.7

And this is what I have in my .zshrc file.

# pyenv config
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init -)"
fi

Your PYENV_ROOT and PATH in .zshrc looks odd. According to the installation guide, they should looke something like above. Make them like above.

It seems instead of running echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.zshrc in terminal, you put it in .zshrc directly. Remove the code block starting echo -e and run the code in the terminal instead. Then your .zshrc will look like something above.

Now try running pyenv install version_to_install, where version_to_install is python you want to install with pyenv. For exmaple

pyenv install 3.7.7

Then it will install the specific version. After it's installed, run pyenv versions again and see if you see the installed python version too in the list.

harryghgim
  • 1,340
  • 4
  • 12
  • 33
  • 1
    So I had already installed python 3.8.5 using `brew` and I just want `pyenv` to refer to it, I don't want to re-install it. – linuxNoob Aug 20 '20 at 02:55
  • I get `/Users/pq0252/.pyenv/shims:/Users/pq0252/.pyenv/bin:/Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin` in `echo $PATH` after making the changes you suggested but I still don't see `pyenv versions` showing the python version. – linuxNoob Aug 20 '20 at 03:02
  • @linuxNoob Installing `pyenv` with `brew` and installing a separate python version with `pyenv install python_version` are two different things. I'm telling you to run `pyenv install`(which will install a separate python version) command, not `brew install`(which will install pyenv software itself) – harryghgim Aug 20 '20 at 03:03
  • I'm saying I installed python 3.8.5 using `brew` before I installed `pyenv` using `brew`. – linuxNoob Aug 20 '20 at 03:07
  • 1
    if you want to see 3.8.5 when you run `pyenv versions`, you need to install it using `pyenv install`. System python versions(version you already have before installing pyenv) will appear just as `system`. I'm using python 3.8.5 installed by brew, and this is my system python – harryghgim Aug 20 '20 at 03:08
  • sounds like I can safely assume that the version is 3.8.5 then? – linuxNoob Aug 20 '20 at 03:09
  • @linuxNoob Yes. `pyenv` has nothing to do with referring to system python version. What you see when you run `python --version` is your python version installed. If you want to see where is that python version is referring, run `which python3`, then it will show the python version interpreter path something like this: `/Users/gwanghyeongim/.pyenv/shims/python3` – harryghgim Aug 20 '20 at 03:12
  • I was under the impression that `pyenv` would change the system version as I need it, sounds like not though. Not sure how it will be useful then. – linuxNoob Aug 20 '20 at 03:15
  • @linuxNoob Not so unless you install separate python version to use it with separate dependency like `virtualvenv` for specific python version project. – harryghgim Aug 20 '20 at 03:19
  • so if I install something which needs python say `Airflow`, will it by default use the python version on my system? On my system `python --version` is 2.7.16 – linuxNoob Aug 20 '20 at 03:26
  • 1
    It sounds like `pyenv` is useful only if I use it to install python, if not it's pointless. – linuxNoob Aug 20 '20 at 03:34
  • 1
    You can set different version either globally by running `pyenv global python_version` or locally in your project folder by running `pyenv local python_version`. `Airflow` is installable as python package, so if you set a specific python version where `Airflow` to be installed on and make `virtualvenv` or `venv` and install `Airflow` on that virtual environment, pyenv can serve your needs. – harryghgim Aug 20 '20 at 03:49
  • `pyenv global 3.8.5` gives me version 3.8.5 not installed. I'm not sure what `virtualenv` does, need to look into that. – linuxNoob Aug 20 '20 at 03:50
  • I suggest you look into python dependencies like `virtualvenv`, `venv` or `mkvirtualenv` along with pyenv. Setting python version is pyenv's job, and separating projects where python packages are installed on is dependencies' job. – harryghgim Aug 20 '20 at 03:54
  • Ensure you have python version installed first before running `pyenv global` or `pyenv local`. Besides, you don't need `pyenv global 3.8.5` since your default python version is 3.8.5 globally unless specified otherwise by you. – harryghgim Aug 20 '20 at 03:58
  • `pyenv global` gives system but `python --version` gives 2.7.16 – linuxNoob Aug 20 '20 at 04:10
  • What about `python3 --version`? – harryghgim Aug 20 '20 at 04:18
  • That gives 3.8.5 – linuxNoob Aug 20 '20 at 04:19