无法在ubuntu上运行python3

时间:2016-07-16 14:17:47

标签: python python-2.7 python-3.x ubuntu

我无法在ubuntu 14.04上运行python3

alias python=python3
python --version

输出:

Python 2.7.6

python3 --version

给出相同的输出

据我所知,python3应该预先安装在系统上?

我试图跑:

sudo apt-get install python3

但是有一个错误:

  Setting up idle-python3.4 (3.4.3-1ubuntu1~14.04.3) ...
  File "/usr/lib/python3.4/compileall.py", line 120
    print('*** ', end='')
                     ^
SyntaxError: invalid syntax
dpkg: error processing package idle-python3.4 (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 idle-python3.4

2 个答案:

答案 0 :(得分:5)

检查是否安装了python3

python3 --version

alias python=python3添加到~/.bashrc~/.bash_aliases文件中。

您必须退出然后重新登录。

我建议将python3用于python 3.x.有很多程序取决于python 2.x所以最好不要删除它。但是您可以将其卸载:sudo apt-get remove python2.7

在卸载Python 2.7之前,请阅读this

答案 1 :(得分:4)

你误解了别名是如何工作的。您需要通过hash -r重置哈希表(有关详细信息,请参阅man bash)。

此外:

edd@max:~$ python3 --version
Python 3.5.1+
edd@max:~$ lsb_release -d
Description:    Ubuntu 16.04 LTS
edd@max:~$ 

edd@max:~$ ls -l /usr/bin/python*
lrwxrwxrwx 1 root root       9 Dec  9  2015 /usr/bin/python -> python2.7
lrwxrwxrwx 1 root root       9 Dec  9  2015 /usr/bin/python2 -> python2.7
-rwxr-xr-x 1 root root 2629712 Aug 11  2011 /usr/bin/python2.6
-rwxr-xr-x 1 root root 3546104 Jul  2 14:05 /usr/bin/python2.7
lrwxrwxrwx 1 root root      33 Jul  2 14:05 /usr/bin/python2.7-config -> x86_64-linux-gnu-python2.7-config
lrwxrwxrwx 1 root root      16 Dec  9  2015 /usr/bin/python2-config -> python2.7-config
lrwxrwxrwx 1 root root       9 Mar 23 06:00 /usr/bin/python3 -> python3.5
lrwxrwxrwx 1 root root      11 Oct 19  2012 /usr/bin/python3.2 -> python3.2mu
-rwxr-xr-x 1 root root 2863832 Oct 19  2012 /usr/bin/python3.2mu
-rwxr-xr-x 2 root root 4439120 Mar 31 06:51 /usr/bin/python3.5
-rwxr-xr-x 2 root root 4439120 Mar 31 06:51 /usr/bin/python3.5m
lrwxrwxrwx 1 root root      10 Mar 23 06:00 /usr/bin/python3m -> python3.5m
lrwxrwxrwx 1 root root      16 Dec  9  2015 /usr/bin/python-config -> python2.7-config
lrwxrwxrwx 1 root root      58 Mar 25 17:01 /usr/bin/pythontex -> ../share/texlive/texmf-dist/scripts/pythontex/pythontex.py
-rwxr-xr-x 1 root root     306 Mar 25 17:01 /usr/bin/pythontex3
edd@max:~$ 

您希望查看dpkg-alternatives以将默认值从python2切换为python3。我要小心,因为有些系统脚本可能希望python成为版本2.