为什么在我的 Kali Linux 中,将用户安装的 python3.9.5 设置为默认 python3 会导致“权限被拒绝:python3”或“python3:找不到命令”?

为什么在我的 Kali Linux 中,将用户安装的 python3.9.5 设置为默认 python3 会导致“权限被拒绝:python3”或“python3:找不到命令”?

背景

我正在使用全新安装的 Kali Linux 2023.1,它附带了 Python3.11.1。我需要安装MobSF,它需要python3对应python3.8和python3.10之间的版本。

所以我决定安装 pyenv 然后3.9.5通过pyenv install -v 3.9.5.然后我执行了pyenv global 3.9.5。然后我执行了python3 --version,我得到了permission denied

所以我决定使用update-alternatives这个新安装的python3.9.5默认值。我执行了以下命令。

sudo update-alternatives --install /usr/bin/python3 python3 /home/user/.pyenv/versions/3.9.5/bin 1

然后我执行了sudo update-alternatives --config python3它给了我

└─$ sudo update-alternatives --config python3
[sudo] password for user: 
There are 2 choices for the alternative python3 (providing /usr/bin/python3).

  Selection    Path                                      Priority   Status
------------------------------------------------------------
* 0            /usr/bin/python3.11                        1         auto mode
  1            /home/user/.pyenv/versions/3.9.5/bin       1         manual mode
  2            /usr/bin/python3.11                        1         manual mode

Press <enter> to keep the current choice[*], or type selection number: 

我进入了1

现在当我执行时sudo update-alternatives --config python3,我得到

└─$ sudo update-alternatives --config python3
[sudo] password for user: 
There are 2 choices for the alternative python3 (providing /usr/bin/python3).

  Selection    Path                                  Priority   Status
------------------------------------------------------------
  0            /home/user/.pyenv/versions/3.9.5/bin   1         auto mode
* 1            /home/user/.pyenv/versions/3.9.5/bin   1         manual mode
  2            /usr/bin/python3.11                    1         manual mode

Press <enter> to keep the current choice[*], or type selection number: 

问题

现在当我跑步时python3 -V,我得到

┌──(user㉿kali)-[~]
└─$ python3 -V       
zsh: permission denied: python3
                                                                                                                                                                                                    
┌──(user㉿kali)-[~]
└─$ sudo python3 -V                          
[sudo] password for user: 
sudo: python3: command not found

现在我不知道该怎么办。请问有人可以指导吗?


评论中的详细信息

评论: 那么,那里有文件吗?您告诉系统使用 /home/user/.pyenv/versions/3.9.5/bin/python3,这个存在吗?它可以执行吗?

以下是/home/user/.pyenv/versions/3.9.5/bin/的情况:

┌──(user㉿kali)-[~/.pyenv/versions/3.9.5/bin]
└─$ ls -al                      
total 116
drwxrwxrwx 2 user user  4096 Apr 28 07:10 .
drwxrwxrwx 6 user user  4096 Apr 28 03:24 ..
lrwxrwxrwx 1 user user     8 Apr 28 03:24 2to3 -> 2to3-3.9
-rwxrwxrwx 1 user user   127 Apr 28 03:24 2to3-3.9
lrwxrwxrwx 1 user user     7 Apr 28 03:24 idle -> idle3.9
lrwxrwxrwx 1 user user     7 Apr 28 03:24 idle3 -> idle3.9
-rwxrwxrwx 1 user user   125 Apr 28 03:24 idle3.9
lrwxrwxrwx 1 user user     6 Apr 28 03:24 pip -> pip3.9
-rwxrwxrwx 1 user user   255 Apr 28 03:24 pip3
-rwxrwxrwx 1 user user   255 Apr 28 03:24 pip3.9
lrwxrwxrwx 1 user user     8 Apr 28 03:24 pydoc -> pydoc3.9
lrwxrwxrwx 1 user user     8 Apr 28 03:24 pydoc3 -> pydoc3.9
-rwxrwxrwx 1 user user   110 Apr 28 03:24 pydoc3.9
lrwxrwxrwx 1 user user     9 Apr 28 03:24 python -> python3.9
lrwxrwxrwx 1 root     root        25 Mar 13 08:18 python3 -> /etc/alternatives/python3
-rwxrwxrwx 1 user user 17576 Apr 28 03:23 python3.9
-rwxrwxrwx 1 user user  3111 Apr 28 03:24 python3.9-config
-rwxrwxrwx 1 user user 65392 Apr 28 03:24 python3.9-gdb.py
lrwxrwxrwx 1 user user    16 Apr 28 03:24 python3-config -> python3.9-config
lrwxrwxrwx 1 user user    16 Apr 28 03:24 python-config -> python3.9-config

正如我们所看到的,这python3是一个指向 的符号链接/etc/alternatives/python3。所以下面的截图显示了情况/etc/alternatives/python3

┌──(user㉿kali)-[/etc/alternatives/python3]
└─$ ls -al
total 116
drwxrwxrwx 2 user user  4096 Apr 28 07:10 .
drwxrwxrwx 6 user user  4096 Apr 28 03:24 ..
lrwxrwxrwx 1 user user     8 Apr 28 03:24 2to3 -> 2to3-3.9
-rwxrwxrwx 1 user user   127 Apr 28 03:24 2to3-3.9
lrwxrwxrwx 1 user user     7 Apr 28 03:24 idle -> idle3.9
lrwxrwxrwx 1 user user     7 Apr 28 03:24 idle3 -> idle3.9
-rwxrwxrwx 1 user user   125 Apr 28 03:24 idle3.9
lrwxrwxrwx 1 user user     6 Apr 28 03:24 pip -> pip3.9
-rwxrwxrwx 1 user user   255 Apr 28 03:24 pip3
-rwxrwxrwx 1 user user   255 Apr 28 03:24 pip3.9
lrwxrwxrwx 1 user user     8 Apr 28 03:24 pydoc -> pydoc3.9
lrwxrwxrwx 1 user user     8 Apr 28 03:24 pydoc3 -> pydoc3.9
-rwxrwxrwx 1 user user   110 Apr 28 03:24 pydoc3.9
lrwxrwxrwx 1 user user     9 Apr 28 03:24 python -> python3.9
lrwxrwxrwx 1 root     root        25 Mar 13 08:18 python3 -> /etc/alternatives/python3
-rwxrwxrwx 1 user user 17576 Apr 28 03:23 python3.9
-rwxrwxrwx 1 user user  3111 Apr 28 03:24 python3.9-config
-rwxrwxrwx 1 user user 65392 Apr 28 03:24 python3.9-gdb.py
lrwxrwxrwx 1 user user    16 Apr 28 03:24 python3-config -> python3.9-config
lrwxrwxrwx 1 user user    16 Apr 28 03:24 python-config -> python3.9-config

相关内容