Installed Python 3.8 on Ubuntu, but it's not the default

前端 未结 2 1478
暗喜
暗喜 2021-01-05 19:56

I have downloaded Python 3.8 on my Ubuntu 16.04 and if i write python3.8 it shows it is present, but when I write python --version I am getting my

相关标签:
2条回答
  • 2021-01-05 20:28

    Everything depends on how you installed the python3.8. Many methods wouldn't update default symlinks for you.

    If you do something like: sudo ln -s /usr/bin/python3.8 /usr/local/bin/python and run python --version afterward it should solve your issue.

    If you python3.8 binary is not in /usr/bin/python3.8 update your symlink path accordingly.

    Keep in mind that some apps dependent on specific features of the lower python version might not work correctly. With Python3 the probability is low though.

    0 讨论(0)
  • 2021-01-05 20:46

    Set an alias:

    alias python=python3.8
    

    Then running python in Bash will run python3.8.

    To make the change permanent, put the alias line in ~/.bashrc. It will take effect when you open Bash.


    Symlinks

    Why not symlink /usr/bin/python to python3.8?

    Ubuntu follows PEP 394 which says the python command should point to Python 2. However an alias works since it only affects your shell. It doesn't even affect scripts you write, meaning if you want a script to run in Python 3.8, you'll have to write it explicitly in the shebang, e.g. #!/usr/bin/env python3.8 instead of #!/usr/bin/env python.

    Why not at least symlink /usr/bin/python3 to python3.8?

    Some things will break since there are version-specific libraries. For example _gi is not available for Python 3.8 on Ubuntu 16.04, so Gnome Terminal will not open. See Gnome terminal will not start on Ask Ubuntu for an example.


    More details

    • How to make 'python' program command execute Python 3? on Ask Ubuntu
    0 讨论(0)
提交回复
热议问题