How to downgrade python version from 3.8 to 3.7 (mac)
Solution 1
Consider installing pyenv
with Homebrew on macOS
brew update
brew install pyenv
OR Clone the repository to get the latest version of pyenv
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
Define your environment variables
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
source ~/.bash_profile
Restart your shell so the path changes take effect
exec "$SHELL"
Verify the installation and check the available python
versions
pyenv install --list
Install the required python
version
pyenv install 3.7
Set it as your global version after installation
pyenv global 3.7
Verify your current python
version the system is using
python3 --version
Solution 2
I recommend you to install and use pyenv, a Python Version Management. Once intalled pyenv, install python 3.7:
pyenv install 3.7
And then set the environment PYENV_VERSION
to version of python you want to use, on this case will be 3.7:
pyenv shell 3.7
Solution 3
brew only approach.
rm -rf $(brew --repository)/Library/Taps/company
brew tap-new company/team
brew extract [email protected] company/team --version=3.7.9
HOMEBREW_NO_AUTO_UPDATE=1 brew install company/team/[email protected]
brew link --force company/team/[email protected]
This creates a local tap, extracts python 3.7.X to a formula in that local tap and then installs and links that formula
The created local tap and the new formula file can be found in
$(brew --repository)/Library/Taps/company/homebrew-team
Related videos on Youtube
user13902742
Updated on July 09, 2022Comments
-
user13902742 almost 2 years
I'm using Python & okta-aws tools and in order to fetch correct credentials on aws I need to run okta-aws init. But got an error message of
Could not read roles from Okta
and the system prompted that"Your Pipfile requires python_version 3.7, but you are using 3.8.3 (/usr/local/Cellar/o/1.1.4/l/.venv/bin/python)
.I've tried to search all the Pipfiles on the mac and it seems that the Pipflie under my
~/Pipfile
and/usr/local/Cellar/[email protected]/3.8.3_2/libexec/bin/Pipfile
all have the same python version of 3.8, while the Pipfile under my/usr/local/Cellar/okta-aws-tools/1.1.4/libexec/Pipfile
hasrequired python_version = 3.7
.I've been struggling with this for a while and really not sure how I can fix this.
-
Almas Dusal over 3 yearsAlso eval "$(pyenv init -)" to .bash_profile or .bashrc required. Then source .bashrc and reopened terminal is worked for me.
-
C8H10N4O2 over 3 yearsFor newbies, you might clarify that you need to either brew install or git clone (but not both) depending on whether you need the latest version.
-
AnupamChugh over 3 yearsI just wanted to add that to finally set the pyenv global 3.7, you need to use the default macOS terminal. It doesn't work on the iTerm2.
-
soMuchToLearnAndShare over 3 years@almas Dusal, can you be a bit more explicit what you mean by eval .... to ... using maybe command?.... got it it means add
eval "$(pyenv init -)"
to the .zshrc or .bashrc file -
soMuchToLearnAndShare over 3 years@Shayan it would be nice if you could add the pyenv init part into the answer.
-
Dr. Freddy Dimethyltryptamine about 3 yearsFailing on M1 chip
-
Mehdi Abbassi almost 3 yearsI did all you suggested to downgrade from 3.9 to 3.8, but at the end python3 --version gives me python 3.9
-
Micah.Fay over 2 yearsI had to also do this for pyenv to work to downgrade from 3.9 to 3.7 github.com/pyenv/pyenv/issues/849#issuecomment-863456765
-
Hristo Todorov over 2 yearsI had to add
eval "$(pyenv init --path)"
in order to work -
Gino Mempin over 2 yearsHow exactly did you "Downgraded python 3.9 to 3.8.12" and set it "as global"? Because that was the exact question, the OP was struggling to downgrade the Python used in the project from 3.8 to 3.7. So a more detailed set of steps would be useful.
-
PCM over 2 yearsWhile this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value.
-
soMuchToLearnAndShare over 2 years
eval "$(pyenv init -)"
used to work for me, and for somereason our IT installed some stuff on my mac os, now i have to useeval "$(pyenv init --path)"
-
soMuchToLearnAndShare over 2 yearsif you happen to have SDKMAN installed, be sure your command like below is not overriding or setting to a wrong path
export PATH="/usr/local/opt/[email protected]/bin:$PATH"
-
therightstuff almost 2 yearsDid you need to reinstall
xcode-select
in order for @Shayan's solution to work? If so, any idea why? I'm on an M1 Mac and the default Python version isn't updated even though bothpyenv
'sglobal
andshell
versions are set correctly after restarting the terminal. -
therightstuff almost 2 yearsI don't see how reinstalling xcode-select is relevant (I'm using an M1 Mac and it was already installed), but the only addition I have to @Shayan's solution to make it work is to follow stackoverflow.com/a/69378384/2860309 and add
eval "$(pyenv init --path)"
into the.zshrc
file.