如何在终端中切换Python版本? [英] How to switch Python versions in Terminal?

查看:525
本文介绍了如何在终端中切换Python版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Mac默认安装了Python 2.7,但我想改用Python 3.6.1.

My Mac came with Python 2.7 installed by default, but I'd like to use Python 3.6.1 instead.

如何更改终端(在Mac OS上)中使用的Python版本?

How can I change the Python version used in Terminal (on Mac OS)?

请清楚地说明,并且不提供任何第三方版本管理器的建议.

推荐答案

最简单的方法是向python3添加别名,以始终指向已安装的本机python.最后将此行添加到$HOME目录中的.bash_profile文件中,

The simplest way would be to add an alias to python3 to always point to the native python installed. Add this line to the .bash_profile file in your $HOME directory at the last,

alias python="python3"

这样做可以使更改反映在每个打开的交互式shell上.

Doing so makes the changes to be reflected on every interactive shell opened.

这篇关于如何在终端中切换Python版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆