0

I created a virtual env using this method within my VSCode Studio.

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.

However, if I try to activate the env in another terminal (outside VSCode), I am able to see the correct version. How can I fix it within VSCode?

Within VSCode, I see these:

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 terminal (outside VS):

/usr/local/Caskroom/miniconda/base/bin/python
x89
  • 2,798
  • 5
  • 46
  • 110
  • VSCode does not get anything from `.zshrc` unless you launch it from a shell. A process inherits environment variables from the process that launched it. – molbdnilo Feb 02 '22 at 13:20
  • so, what's the solution? since I created the virtual env within the VS code, shouldn't it already work there? @molbdnilo – x89 Feb 02 '22 at 13:28
  • Well, it should. There's a setting in VSCode about inheriting the environment in the VSCode terminal. Search for "environment" and locate "Inherit Env" for the terminal. Make sure that it's checked and start a new shell. – molbdnilo Feb 02 '22 at 13:44
  • it's already checked. also tried reloading and updating VS code but it's still showing the wrong version @molbdnilo – x89 Feb 02 '22 at 14:23

0 Answers0