简体   繁体   中英

In Kali Linux, why do I only see python2 and python3 binaries (NOT a 'python' binary) in /usr/bin/ and get "python command not found"

I am running latest version of Kali Linux:

uname -a                           
Linux User 5.14.0-kali4-amd64 #1 SMP Debian 5.14.16-1kali1 (2021-11-05) x86_64 GNU/Linux

It already came with Python 3.9.8. But I needed to install Python 2.7. So I first installed it with sudo apt install python2.7.18. But following happened:

python -V        
Command 'python' not found, did you mean:
  command 'python3' from deb python3
  command 'python' from deb python-is-python3

python2 -V  
Python 2.7.18

python3 -V       
Python 3.9.8

Also:

which python
python not found

WHAT I TRIED:

I checked locations such as /usr/opt/ , /usr/bin/ , /usr/share/ etc. I checked /usr/bin and found python2 and python3 binaries:

在此处输入图像描述

So I reckoned that python environment variable is not set. I added python=/usr/bin/python2 to /etc/environment and then did source /etc/environment . But that did not help.

Then I checked /usr/share and found that python folder Was there.

在此处输入图像描述


Then I did some research on the internet and found pyenv , which apparently allows us to install and use multiple Python versions without them conflicting with each other. So I followed all steps in the given guide to isntall Python 2.7.18 and set it as default. But that did not solve the problem either

sudo apt install -y build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python3-openssl git

curl https://pyenv.run | bash

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc     

echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc

echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.zshrc

exec $SHELL

pyenv 2.2.3

pyenv install 2.7.18

pyenv global 2.7.18

Then I checked:

pyenv versions                                                                                                                                                                              1 ⨯
  system
* 2.7.18 (set by /home/bruno/.pyenv/version)

So far so good. But then:

python           
Command 'python' not found, did you mean:
  command 'python3' from deb python3
  command 'python' from deb python-is-python3

Moreover, to confirm:

在此处输入图像描述

Because that distribution wants to be clear about which version of Python you're running, and it's perfectly allowed to do so .

In short, you'll have to use python3 to run Python 3.x, and python2 (if such a symlink gets set up by pyenv , or if you apt install python2.7 (if it's even available on Kali)) to run Python 2.x.

Please remember Python 2.x is EOL, and you shouldn't use it for any new development.

Manually adding path to /home/bruno/.pyenv/versions/2.7.18/bin to $PATH environment variable solved the python command not found for me, because that directory contains python binary.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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