python3 --version 在搞乱环境后返回 python 2.7

python3 --version 在搞乱环境后返回 python 2.7

我试图创建一个新的 python 虚拟环境,然后我运行sudo virtualenv xxx,我也可能会尝试其他类似的评论。之后,我的python3就乱了。可以看到相关注释的输出:

$ python --version
Python 2.7.12
$ python3 --version
Python 2.7.12
$ python3.5 --version
Python 2.7.12
$ which python3
/usr/bin/python3
$ which python3.5
/usr/bin/python3.5
$ ls -lh /usr/bin/python*
lrwxrwxrwx 1 root root    9 Nov 24  2017 /usr/bin/python -> python2.7
lrwxrwxrwx 1 root root   16 Nov 24  2017 /usr/bin/python-config -> python2.7-config
lrwxrwxrwx 1 root root    9 Nov 24  2017 /usr/bin/python2 -> python2.7
lrwxrwxrwx 1 root root   16 Nov 24  2017 /usr/bin/python2-config -> python2.7-config
-rwxr-xr-x 1 root root  319 Feb 24  2016 /usr/bin/python2-jsonschema
-rwxr-xr-x 1 root root  151 Nov 23  2015 /usr/bin/python2-pbr
-rwxr-xr-x 1 root root 3.4M Dec  4  2017 /usr/bin/python2.7
lrwxrwxrwx 1 root root   33 Dec  4  2017 /usr/bin/python2.7-config -> x86_64-linux-gnu-python2.7-config
lrwxrwxrwx 1 root root    9 May 26  2017 /usr/bin/python3 -> python3.5
lrwxrwxrwx 1 root root   16 Mar 23  2016 /usr/bin/python3-config -> python3.5-config
-rwxr-xr-x 2 root root 3.4M Jun 23 17:37 /usr/bin/python3.5
lrwxrwxrwx 1 root root   33 Nov 28  2017 /usr/bin/python3.5-config -> x86_64-linux-gnu-python3.5-config
-rwxr-xr-x 2 root root 3.4M Jun 23 17:37 /usr/bin/python3.5m
lrwxrwxrwx 1 root root   34 Nov 28  2017 /usr/bin/python3.5m-config -> x86_64-linux-gnu-python3.5m-config
lrwxrwxrwx 1 root root   10 May 26  2017 /usr/bin/python3m -> python3.5m
lrwxrwxrwx 1 root root   17 Mar 23  2016 /usr/bin/python3m-config -> python3.5m-config

而且由于 python3 被破坏,使用 python3 的 lsb_release 也被破坏:

$ lsb_release -a
  File "/usr/bin/lsb_release", line 64
    print("No LSB modules are available.", file=sys.stderr)
                                               ^
SyntaxError: invalid syntax

由于 lsb_release 已损坏,我很难使用 apt。

我尝试重新安装 python3 但它不允许我,因为我在公司网络中:

$ sudo apt-get install --reinstall python3.5

The following additional packages will be installed:
  libpython3.5 libpython3.5-dev libpython3.5-minimal libpython3.5-stdlib python3.5-dev python3.5-minimal
Suggested packages:
  python3.5-venv python3.5-doc binfmt-support
The following packages will be upgraded:
  libpython3.5 libpython3.5-dev libpython3.5-minimal libpython3.5-stdlib python3.5 python3.5-dev python3.5-minimal
7 upgraded, 0 newly installed, 0 to remove and 307 not upgraded.
Need to get 43.5 MB of archives.
After this operation, 5120 B disk space will be freed.
Do you want to continue? [Y/n] y

...<just trimming for easy reading>

E: Failed fo fetch <some network internal address> 403 Forbidden

E: Failed fo fetch <some network internal address> 403 Forbidden

E: Failed fo fetch <some network internal address> 403 Forbidden

E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

我尝试添加 ppa:deadsnakes/ppa 来绕过这个内部网络,我得到了这个结果:

$ sudo add-apt-repository ppa:deadsnakes/ppa
  File "/usr/bin/lsb_release", line 64
    print("No LSB modules are available.", file=sys.stderr)
                                               ^
SyntaxError: invalid syntax
Traceback (most recent call last):
  File "/usr/bin/add-apt-repository", line 22, in <module>
    sys.stdout.detach(), encoding="UTF-8", line_buffering=True)
AttributeError: 'file' object has no attribute 'detach'

所以,看起来python3和python2的二进制文件是相同的,并且由于网络限制和ubuntu的鸡蛋蛋的事情,我无法从apt安装python3,你需要python来安装python。

我真的需要帮助,不幸的是,从头开始重新安装 ubuntu 根本不是一个选择。

我很感激任何帮助。谢谢你!

可能的相关文章:

python3指向python2.7.6

https://www.linuxquestions.org/questions/ubuntu-63/python3-v-returns-python-2-7-12-can%27t-get-python3-to-work-4175650241/

https://askubuntu.com/questions/853377/error-with-lsb-release-a-in-ubuntu-16-04-xenial

https://forums.linuxmint.com/viewtopic.php?t=245836

ps:操作系统是Ubuntu 16.04,但这个问题与操作系统无关,也可以用其他版本重新创建它。

相关内容