首页 > 解决方案 > 如何将 python 版本从 3.8 降级到 3.7 (mac)

问题描述

我正在使用 Python 和 okta-aws 工具,为了在 aws 上获取正确的凭据,我需要运行 okta-aws init。但是得到一个错误信息Could not read roles from Okta并且系统提示那个"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)

我试图搜索mac上的所有Pipfiles,似乎我下的Pipflie~/Pipfile/usr/local/Cellar/python@3.8/3.8.3_2/libexec/bin/Pipfile都具有相同的python 3.8版本,而我下的Pipfile /usr/local/Cellar/okta-aws-tools/1.1.4/libexec/Pipfilerequired python_version = 3.7.

我已经为此苦苦挣扎了一段时间,真的不知道如何解决这个问题。

标签: pythonvirtualenvoktapipenvpython-3.8

解决方案


考虑pyenv在 macOS 上使用 Homebrew安装

brew update
brew install pyenv

克隆存储库以获取最新版本的pyenv

 git clone https://github.com/pyenv/pyenv.git ~/.pyenv

定义环境变量

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

重新启动您的 shell,使路径更改生效

exec "$SHELL"

验证安装并检查可用python版本

pyenv install --list

安装所需python版本

pyenv install 3.7

安装后将其设置为您的全局版本

pyenv global 3.7

验证python系统正在使用的当前版本

python3 --version

推荐阅读