把linux环境中的python设置为python3

执行python脚本时,老是出现一些错误,后来发现只要手动执行

python3 filename  就没有错误了。这时才觉得要把环境中默认的python设置为python3.具体执行如下:


[(45) root@Fedora~/Note/python]#file /usr/bin/python
/usr/bin/python: symbolic link to `python2'
[(46) root@Fedora~/Note/python]#python
python      python2     python2.7   python3     python3.4   python3.4m
[(46) root@Fedora~/Note/python]#which python2
/usr/bin/python2
[(47) root@Fedora~/Note/python]#which python3
/usr/bin/python3
[(48) root@Fedora~/Note/python]#mv /usr/bin/python /usr/bin/python_bk
[(49) root@Fedora~/Note/python]#ln -s /usr/bin/python3 /usr/bin/python
[(50) root@Fedora~/Note/python]#file /usr/bin/python
/usr/bin/python: symbolic link to `/usr/bin/python3'
[(51) root@Fedora~/Note/python]#python -V
Python 3.4.1

原理就是/usr/bin/python是一个对python2的链接,只要把这个链接修改为python3的就可以了。

你可能感兴趣的:(python)