当你安装 Linux 时,安装过程有可能同时为你提供多个可用的 Python 版本,因此系统中会存在多个 Python 的可执行二进制文件。一般Ubuntu默认的Python版本都为2.x, 如何改变Python的默认版本呢?下面来一起看看吧。
你可以按照以下方法使用 ls 命令来查看你的系统中都有那些 Python 的二进制文件可供使用:
看下当前路径
python: /usr/bin/python2.7
/usr/bin/python3.7m
/usr/bin/python2.7-config
/usr/bin/python3.7-config
/usr/bin/python3.7
/usr/bin/python3.7m-config
/usr/bin/python
/usr/lib/python2.7
/usr/lib/python3.7
/etc/python2.7
/etc/python3.7
/etc/python
/usr/local/lib/python2.7
/usr/local/lib/python3.7
/usr/include/python2.7
/usr/include/python3.7m /
usr/include/python3.7
/usr/share/python
/usr/share/man/man1/python.1.gz
whereis python
/usr/bin/python /usr/bin/python2.7-config /usr/bin/python3 /usr/bin/python3.7m /usr/bin/python3m
/usr/bin/python2 /usr/bin/python2-config /usr/bin/python3.7 /usr/bin/python3.7m-config /usr/bin/python3m-config
/usr/bin/python2.7 /usr/bin/python2-pbr /usr/bin/python3.7-config /usr/bin/python3-config /usr/bin/python-config
查看默认的 Python 版本信息
python --version
淦,我知道就是这样.
基于用户修改 Python 版本:
想要为某个特定用户修改 Python 版本,只需要在其 home 目录下创建一个 alias(别名) 即可。打开该用户的 ~/.bashrc文件,添加新的别名信息来修改默认使用的 Python 版本。
进入目录,sudo一下吧~
alias python='/usr/bin/python3.4'
一旦完成以上操作,重新登录或者重新加载 .bashrc 文件,使操作生效。
. ~/.bashrc
这个地方卡住了~
重启.失败了~
检查当前的 Python 版本。
$ python --version
Python 3.4.2
将新装的/usr/local/python/bin添加到环境变量中(但这个只是临时的做法,退出python后就无效了)
永久有效的做法是:进入/etc/profile,
PATH=$PATH:/usr/local/python/bin
export PATH
还是失败了~,继续