当前位置:首页 > 操作系统 > MacOs

mac命令行切换python版本

brew安装anaconda3

<code>brew cask install anaconda3
</code>

安装之后打开路径查看:/usr/local/anaconda3/bin
mac命令行切换python版本 - 文章图片


anaconda3环境变量设置

<code>vim ~/.zshrc

export PATH=/usr/local/anaconda3/bin:$PATH

source ~/.zshrc
</code>

验证

<code>conda --version
# 看到版本好就成功了
</code>

安装双版本

<code>conda create --name python2 python=2.7

conda create --name python3 python=3.7
</code>

查看目录 /usr/local/anaconda3/envs/
mac命令行切换python版本 - 文章图片


python环境变量设置

<code>export PATH="/usr/local/anaconda3/envs/python3:$PATH"

# 重新加载一下系统环境变量
. ~/.zshrc
</code>
<code>?  ~ python2

WARNING: Python 2.7 is not recommended.
This version is included in macOS for compatibility with legacy software.
Future versions of macOS will not include Python 2.7.
Instead, it is recommended that you transition to using 'python3' from within Terminal.

Python 2.7.16 (default, Dec 13 2019, 18:00:32)
[GCC 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.32.4) (-macos10.15-objc-s on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>



?  ~ python3
Python 3.7.6 (default, Jan  8 2020, 13:42:34)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
</code>

参考

https://www.cnblogs.com/zhoulin1234/p/9893055.html


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐