简体   繁体   English

无法在ubuntu上运行python3

[英]can't run python3 on ubuntu

I can't run python3 on ubuntu 14.04 我无法在Ubuntu 14.04上运行python3

alias python=python3
python --version

outputs: 输出:

Python 2.7.6

and

python3 --version

gives same output 给出相同的输出

As I understand python3 should be preinstalled on the system? 据我了解,python3应该预先安装在系统上吗?

I tried to run: 我试着跑:

sudo apt-get install python3

But there is an error: 但是有一个错误:

  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

Check if python3 is installed: 检查是否安装了python3

python3 --version

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

You must logout then login again. 您必须注销然后再次登录。

I recommend using python3 for python 3.x. 我建议将python3用于python3.x。 There are a lot of programs depending on python 2.x so better not to remove it. 有很多程序取决于python 2.x,因此最好不要删除它。 However you can uninstall it: sudo apt-get remove python2.7 但是您可以卸载它: sudo apt-get remove python2.7

Before uninstalling Python 2.7 read this . 在卸载Python 2.7之前,请阅读此内容

You misunderstand how aliases work. 您误解了别名的工作原理。 You need to reset the hash table via hash -r (see man bash for details). 您需要通过hash -r重置哈希表(有关详细信息,请参见man bash )。

Also: 也:

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

and

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:~$ 

You want to look into dpkg-alternatives to switch the default from python2 to python3 . 您想研究dpkg-alternatives将默认值从python2切换到python3 I'd be careful though as some system scripts may expect python to be version 2. 我会小心一点,因为某些系统脚本可能期望python为版本2。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 crontab 无法在 ubuntu 中运行 python 脚本 - crontab can't run python script in ubuntu 在 ubuntu 上的 Atom 中运行 python3 代码的问题 - problem with Run python3 code in Atom on ubuntu 无法运行命令 python3 manage.py runserver - Can't run the command python3 manage.py runserver miniconda中安装了pandas模块,但是python3无法运行编码 - pandas module installed in miniconda but python3 can't run the coding (Ubuntu) Python3 脚本运行良好,但在 Apache/wsgi 下找不到 selenium 模块 - (Ubuntu) Python3 script runs fine but under Apache/wsgi it can't find selenium module 安装python3后我无法在ubuntu 16.04上打开终端 - I can't open terminal on ubuntu 16.04 after python3 installation 在 Ubuntu VM 中运行 python3 文件时无法打开 lib 'SQL Server Native Client 11.0' - Can't open lib 'SQL Server Native Client 11.0' when running python3 file in Ubuntu VM 无法在opencv3.2中读取mp4(ubuntu,python3) - can't read mp4 in opencv3.2 (ubuntu, python3) 无法打开 lib 'SQL Server Native Client 10.0' Python3、Linux ubuntu - Can't open lib 'SQL Server Native Client 10.0' Python3, Linux ubuntu 我无法在 ubuntu 中创建仅设置为 python3 的虚拟环境 - I can't create a virtual environment set only to python3 in ubuntu
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM