简体   繁体   English

为什么我不能使用 python 虽然它告诉我 python3 已经是最新版本 (3.5.1-3)

[英]why I cant use python though it tell me python3 is already the newest version (3.5.1-3)

I want to use python in my ubuntu.我想在我的 ubuntu 中使用python When I use python command it tell me:当我使用 python 命令时,它告诉我:

dc2-user@10-254-6-144:~$ python
The program 'python' can be found in the following packages:
* python-minimal
* python3
Ask your administrator to install one of them

then I try to install it:然后我尝试安装它:

dc2-user@10-254-6-144:~$ sudo apt-get install python3
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3 is already the newest version (3.5.1-3).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

but as you can see, it seemed that I have already installed python3.5 Then I uninstall it and install it,through但是正如你所看到的,我似乎已经安装了python3.5 然后我卸载它并安装它,通过

sudo apt-get remove python3.5
sudo apt-get install python3.5

but still cant use python command.但仍然无法使用 python 命令。
Generally, I can use python command after install it.I dont know what happend and where I should do next?一般来说,我可以在安装后使用python命令。我不知道发生了什么,下一步应该做什么?

Ubuntu does only install Python 3 and won't add a link from /usr/bin/python3 to /usr/bin/python Ubuntu 只安装 Python 3,不会添加从/usr/bin/python3/usr/bin/python

So you are forced to:所以你被迫:

  • Use python3使用python3

or或者

  • Add a link yourself or an alias or another shell based solution自己添加链接或别名或其他基于 shell 的解决方案

Reference:参考:

Quoting:引用:

  • Python 3 will be the only Python version installed by default. Python 3 将是默认安装的唯一 Python 版本。
  • Python 3 will be the only Python version in any installation media (ie image ISOs) Python 3 将是任何安装介质(即映像 ISO)中唯一的 Python 版本
  • Only Python 3 will be allowed on the Ubuntu touch images.在 Ubuntu 触摸图像上只允许使用 Python 3。
  • All upstream libraries that support Python 3 will have their Python 3 version available in the archive.所有支持 Python 3 的上游库都将在存档中提供其 Python 3 版本。
  • All applications that run under Python 3 will use Python 3 by default.默认情况下,所有在 Python 3 下运行的应用程序都将使用 Python 3。
  • All system scripts in the archive will use Python 3.存档中的所有系统脚本都将使用 Python 3。

and

  • /usr/bin/python will point to Python 3. No, this is not going to happen (unless PEP 394 advocates otherwise, which is doubtful for the foreseeable future). /usr/bin/python 将指向 Python 3。不,这不会发生(除非 PEP 394 提倡否则,这在可预见的未来是值得怀疑的)。 /usr/bin/python and /usr/bin/python2 will point to Python 2.7 and /usr/bin/python3 will point to the latest supported Python 3 version. /usr/bin/python 和 /usr/bin/python2 将指向 Python 2.7 而 /usr/bin/python3 将指向最新支持的 Python 3 版本。

Try using update-alternatives尝试使用更新替代品

I ended up with this issue after trying update-alternatives and incorrectly changing symblinks在尝试更新替代方案并错误地更改符号链接后,我最终遇到了这个问题

Viewing sudo update-alternatives --config python shows you what the system is using.查看sudo update-alternatives --config python显示系统正在使用什么。

You can override that with something like the below:您可以使用以下内容覆盖它:

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 20

Resolve - Too many levels of symbolic links解决 - 符号链接级别过多

If you get Error too many levels of symbolic links Then make sure to double check the symbolic links in /etc/alternatives/如果您收到Error too many levels of symbolic links然后确保仔细检查 /etc/alternatives/ 中的符号链接

cd /etc/alternatives
find . -maxdepth 1 -type l -ls | grep python

The culprit, in the search results you'll see something like this罪魁祸首,在搜索结果中,您会看到类似这样的内容

./python -> /usr/bin/python3

That's a python symlink pointing to python3.这是一个指向 python3 的 python 符号链接。

If you go into /usr/bin you'll probably find that:如果你进入/usr/bin你可能会发现:

./python3 -> /etc/alternatives/python

You have 2 symlinks pointing to each other and hence you get the 'Too many symbolic links' error您有 2 个相互指向的符号链接,因此您会收到“符号链接过多”错误

What you have to do in this case is delete one of them and recreate it.在这种情况下,您需要做的是删除其中一个并重新创建它。 In my case I deleted /etc/alternatives/python symlink and repointed it to python 3.8就我而言,我删除了/etc/alternatives/python符号链接并将其重新指向 python 3.8

cd /etc/alternatives/
sudo rm -r ./python
sudo ln -s /usr/bin/python3.8 ./python

Now typing python, brings up the standard 3.8 welcome, in place of that error in the op现在输入 python,显示标准 3.8 欢迎,代替操作中的错误

Python 3.8.0 (default, Oct 14 2019, 23:13:30)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

您是否尝试过运行sudo python3因为您似乎已经安装了 python

安装 python-minimal 使用命令sudo apt install python-minimal python-minimal 解决了我的问题,我也设法在我的流浪服务器上解决了它。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM