BACKGROUND
I am using a fresh installation of Kali Linux 2023.1, which has come with Python3.11.1. I need to install MobSF, which requires python3 to correspond to version between python3.8 and python3.10.
So I decided to install pyenv and then version 3.9.5 via pyenv install -v 3.9.5. Then I executed pyenv global 3.9.5. Then I executed python3 --version and I got permission denied.
So I decided to use update-alternatives to make this newly installed python3.9.5 as default. I executed the following command.
sudo update-alternatives --install /usr/bin/python3 python3 /home/user/.pyenv/versions/3.9.5/bin 1
Then I executed sudo update-alternatives --config python3 and it gave me
└─$ 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:
and I entered 1.
Now when I execute sudo update-alternatives --config python3, I get
└─$ 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:
QUESTION
Now when I run python3 -V, I get
┌──(user㉿kali)-[~]
└─$ python3 -V
zsh: permission denied: python3
┌──(user㉿kali)-[~]
└─$ sudo python3 -V
[sudo] password for user:
sudo: python3: command not found
Now I don't know what to do. Please can someone guide?
DETAILS FROM COMMENTS
Comment: So, is there a file there? You told the system to use /home/user/.pyenv/versions/3.9.5/bin/python3, does that exist? Is it executable?
Following is the situation of /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
As we can see that python3 is a symlink which points to /etc/alternatives/python3. SO the following screenshot shows the situation of /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
/home/user/.pyenv/versions/3.9.5/bin/python3, does that exist? Is it executable? Also, why are you changing the defaultpython3for the whole system just to run a single tool? Can't you launch the tool with/home/user/.pyenv/versions/3.9.5/bin/python /path/to/tool?sudo ./setup.shwhile the system's python is the first-priority-alternative , I get[ERROR] MobSF dependencies require Python 3.8 - 3.10. You have Python version 3.11.2 or python3 points to Python 3.11.2. And when this python3.9.5 is the default alternative , runningsudo ./setup.shgives[ERROR] python3 is not installed.sudo ./setup.sh, dosudo /home/user/.pyenv/versions/3.9.5/bin/python ./setup.sh, that's what I mean. Please answer the other questions though. Don't answer in comments, add the info to your question./etc/alternatives/python3is a directory and you have a python executable at/etc/alternatives/python3/python3? And why is/home/user/.pyenv/versions/3.9.5/bin/python3a symlink to a directory instead of an executable? That's your main issue.python3is picked up from~/.pyenv/versions/3.9.5/bin, and it's a symbolic link to a directory. I don't know anything about how "alternatives" work or are supposed to work, but that's the source of the issue.