1

I have installed a specific version of Python and it shows when I run pyenv versions:

% pyenv versions
  system
* 3.10.4 (set by .python-version)

However, when I try to use Python (in a venv or without), it always uses the system version instead of the specific version I want to use.

% python3 --version
Python 3.10.6


% python3 -m venv venv3-10-4
% . venv3-10-4/bin/activate
(venv3-10-4) % python3 --version
Python 3.10.6

How do I get my system to use 3.10.4 inside and outside the venv? I tried this, but it didn't help:

pyenv global 3.10.4

I tried setting the version inside the venv too:

(venv3-10-4) > % pyenv local 3.10.4
(venv3-10-4) > % python3 --version
Python 3.10.6
beachCode
  • 3,202
  • 8
  • 36
  • 69
  • Possible [duplicate question](https://stackoverflow.com/questions/1534210/use-different-python-version-with-virtualenv) – Levan Mar 19 '23 at 06:26

1 Answers1

0

I found a solution by tweaking my path in ~/.zshrc (MacOS using the zsh shell in iTerm2).

Note the commented-out line which pointed to 3.10.6--the latest version installed on the machine but not the version I need right now.

# Python
export PATH="~/.pyenv/shims:$PATH"
# export PATH="/var/root/Library/Python/3.10/bin:$PATH"
export PATH="/Users/<username>/.pyenv/versions/3.10.4/bin:$PATH"
alias python='/Users/<username>/.pyenv/versions/3.10.4/bin/python3'
beachCode
  • 3,202
  • 8
  • 36
  • 69