kali命令↓
$ sudo apt update
$ sudo apt install build-essential libssl-dev libbz2-dev libreadline-dev libsqlite3-dev zlib1g-dev
$ wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz
$ tar -xvf Python-2.7.18.tgz
$ cd Python-2.7.18
$ ./configure --enable-optimizations
$ make && sudo make install
$ sudo update-alternatives --config python #选择版本
$ wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
$ sudo ln -s /usr/local/bin/pip2.7 /usr/bin/pip
$ pip uninstall xlrd #卸载高版本
$ python2.7 -m pip install xlrd==1.2.0
#使用 pip 为 Python 2.7 安装 xlrd 版本 1.2.0。为了确保安装到 Python 2.7 的 pip。
你可以使用 python2.7 -m pip 命令。
$ python2.7 -c "import xlrd; print(xlrd.__version__)"
python替换版本↓
#将 Python 2 和 Python 3 的路径添加到 update-alternatives 中。运行以下命令:
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 1
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 2
#使用以下命令来选择默认的 Python 版本:
$ sudo update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/python2 1 auto mode
1 /usr/bin/python2 1 manual mode
2 /usr/bin/python3 2 manual mode
Press <enter> to keep the current choice[*], or type selection number:
#检查当前 Python 版本
$ python --version
方法2↓
#步骤 1:删除当前的 python 符号链接
$ sudo rm /usr/bin/python
#步骤 2:创建一个新的符号链接,指向 Python 2
$ sudo ln -s /usr/bin/python2 /usr/bin/python
#步骤 3:验证更改
$ python --version
#安装 pip 对应的 Python 版本
$ sudo apt install python-pip