0

What's the correct way to activate a Pyenv environment? I want to use an env with python version 3.7.4. I tried this following this tutorial: https://akrabat.com/creating-virtual-environments-with-pyenv/

pyenv install 3.7.4
pyenv virtualenv 3.7.4 apps3
pyenv local apps3
pyenv activate apps3

However, when I check python --versionafter the last command, it still shows me Python 2.7.16, which is my default shell version.

In the tutorial there's also something about global vs local environments. What am I missing? Do I necessarily need to create a global env as well?

which python
/usr/bin/python

Path after activating:

/usr/local/Cellar/pyenv-virtualenv/1.1.5/shims:/Users/neehahammad/.pyenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/Caskroom/miniconda/base/bin:/usr/local/Caskroom/miniconda/base/condabin:/Users/nh/.local/bin:/Users/nh/.local/bin

Path without environment activated:

/usr/local/Cellar/pyenv-virtualenv/1.1.5/shims:/Users/neehahammad/.pyenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/Caskroom/miniconda/base/bin:/usr/local/Caskroom/miniconda/base/condabin:/Users/nh/.local/bin:/Users/nh/.local/bin

already added this in the .zschrc file

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

which python from another termainal (outside VS):

/usr/local/Caskroom/miniconda/base/bin/python
x89
  • 2,798
  • 5
  • 46
  • 110
  • A simple research on google would solve your problem. https://stackoverflow.com/questions/62841295/activate-venv-with-pyenv According to the answer in your case : `pyenv activate apps3` – Rapido Feb 02 '22 at 09:37
  • This doesn't answer your question, but it's worth noting that `venv` is more commonly used, seems easier to use from what I've seen of pyenv (though that's just my opinion), and is available as part of the standard Python distribution. – Kemp Feb 02 '22 at 09:37
  • even with that, when I check the version, it says ```Python 2.7.16```@Rapido – x89 Feb 02 '22 at 09:41
  • What does your `PATH` look like after trying to activate an environment? – md2perpe Feb 02 '22 at 11:09
  • As I thought: you have a Python path before the pyenv path. What is Cellar? Check if the Cellar part is added to `PATH` in `.bashrc` or `.bash_login`. – md2perpe Feb 02 '22 at 12:18
  • I have no idea what cellar is. how do I check? pls see the updated qs with the info about .zshrc @md2perpe How can I edit the export path there? – x89 Feb 02 '22 at 12:28
  • Okay, you're using ZSH, not Bash. That export command prepends `PATH` with the pyenv directory. Somewhere later, the Cellar part is added. Are those that last lines of `.zshrc`? If you open a new console, is it added also then or was it just in this session? If it's always added, perhaps someone more used to ZSH and what files are read at start can help you find the place. – md2perpe Feb 02 '22 at 12:40
  • @md2perpe I realised that when I activate the env in another terminal (outside VSCode), I see the correct python version. However, within VSCode, I always see the wrong version, even if I update the terminal or use a new one inside. I updated the qs with ```which python```info – x89 Feb 02 '22 at 13:15

0 Answers0