目錄
1、需求
2、實現(xiàn)
2.1 安裝 pyenv
2.2 安裝?pyenv-virtualenv
2.3 配置環(huán)境變量
2.4 創(chuàng)建 python 3.9.9?的環(huán)境
2.5 激活環(huán)境,在當前項目目錄中使用,即執(zhí)行 python
1、需求
? ? ? 由于項目所依賴的 python 版本有多個,需要在不同的 python 環(huán)境下運行項目。
2、實現(xiàn)
? ? ? 當前比較流行的方式是使用 pyenv 工具,在不同項目下創(chuàng)建不同版本的 python??運行環(huán)境。
2.1 安裝 pyenv
brew update
brew install pyenv
2.2 安裝?pyenv-virtualenv
github 地址:https://github.com/pyenv/pyenv-virtualenv
采用下載gz 包,然后本地安裝的方式
git clone https://mirror.ghproxy.com/https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv
2.3 配置環(huán)境變量
添加以下內(nèi)容到本地全局環(huán)境變量里:$ sudo vim /etc/profile
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
配置環(huán)境變量生效:$ source /etc/profile
2.4 創(chuàng)建 python 3.9.9?的環(huán)境
pyenv install 3.9.9
pyenv virtualenv 3.9.9 test_python_3.9.9
2.5 激活環(huán)境,在當前項目目錄中使用,即執(zhí)行 python
pyenv activate test_python_3.9.9
文章來源:http://www.zghlxwxcb.cn/news/detail-810355.html
恭喜!接下來就可以使用指定的版本了。文章來源地址http://www.zghlxwxcb.cn/news/detail-810355.html
到了這里,關(guān)于【Python 基礎(chǔ)】-- 在 mac OS 中安裝 多個 python 版本的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!