Linux系统下升级pip的完整步骤

  • Post category:Linux

下面是完整步骤:

  1. 打开命令行(Terminal),输入以下命令检查pip版本:

pip --version
若pip没有安装,可以使用以下命令进行安装:

sudo apt-get install python-pip
注意:若是其他的Linux系统,安装pip的命令可能略有不同。

  1. 使用以下命令升级pip:

sudo pip install --upgrade pip
注意:不要直接使用pip升级pip,因为可能会出现权限问题。

  1. 完成后,再次输入以下命令检查pip版本:

pip --version
这时输出的pip版本应该是最新的版本。

以上就是在Linux系统下升级pip的完整步骤。

下面给出两个示例说明:

示例 1:升级pip版本

假设当前pip版本为9.0.1,我们想要升级为最新版本。打开命令行,输入以下命令:

$ pip --version
pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)

$ sudo pip install --upgrade pip
Collecting pip
  Downloading https://files.pythonhosted.org/packages/bd/4f/7b69c823b1c23a81a25c5c11feb63bc8ed2478f6bd917216a362594a6bc3/pip-21.2.4-py3-none-any.whl (1.6MB)
     |████████████████████████████████| 1.6MB 5.9MB/s
Installing collected packages: pip
  Found existing installation: pip 9.0.1
    Not uninstalling pip at /usr/lib/python2.7/dist-packages, outside environment /usr
Successfully installed pip-21.2.4

$ pip --version
pip 21.2.4 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)

可以看到,pip成功升级到了最新版本。

示例 2:安装pip

假设目前系统中没有安装pip,需要进行安装。打开命令行,输入以下命令:

$ pip --version
Command 'pip' not found, but can be installed with:
sudo apt install python-pip

$ sudo apt-get install python-pip
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  binutils build-essential cpp cpp-7 dh-python dpkg-dev fakeroot g++ g++-7 gcc gcc-7 libasan4 libatomic1 libbinutils libc-dev-bin libc6-dev
  libcc1-0 libcilkrts5 libdpkg-perl libfakeroot libfile-fcntllock-perl libgcc-7-dev libgomp1 libisl19 libitm1 liblsan0 libmpc3 libmpx2
  libpython-all-dev libpython-dev libpython2.7 libpython2.7-dev libpython3-dev libpython3.6 libpython3.6-dev libquadmath0 libreadline7
  libsqlite3-0 libssl1.0-dev libstdc++-7-dev libtinfo5 libubsan0 linux-libc-dev make manpages-dev python-all python-all-dev
  python-asn1crypto python-cffi-backend python-crypto python-cryptography python-dbus python-dev python-ipaddress python-keyring
  python-keyrings.alt python-pip-whl python-secretstorage python-setuptools python-six python-wheel python-xdg python2.7-dev
Suggested packages:
  binutils-doc cpp-doc gcc-7-locales debian-keyring g++-multilib g++-7-multilib gcc-7-doc libstdc++6-7-dbg gcc-multilib autoconf
  automake libtool flex bison gdb gcc-doc gcc-7-multilib libgcc1-dbg libgomp1-dbg libitm1-dbg libatomic1-dbg libasan4-dbg liblsan0-dbg
  libtsan0-dbg libubsan0-dbg libcilkrts5-dbg libmpx2-dbg libquadmath0-dbg libstdc++-7-doc make-doc python-crypto-doc
  python-cryptography-doc python-dbus-doc python-gobject python-dev-doc python2.7-dev-dbg python-setuptools-doc
  python2.7-examples python3-doc python3.6-venv python3.6-doc binfmt-support
The following NEW packages will be installed:
  binutils build-essential cpp cpp-7 dh-python dpkg-dev fakeroot g++ g++-7 gcc gcc-7 libasan4 libatomic1 libbinutils libc-dev-bin libc6-dev
  libcc1-0 libcilkrts5 libdpkg-perl libfakeroot libfile-fcntllock-perl libgcc-7-dev libgomp1 libisl19 libitm1 liblsan0 libmpc3 libmpx2
  libpython-all-dev libpython-dev libpython-pip libpython2.7 libpython2.7-dev libpython3-dev libpython3.6 libpython3.6-dev libquadmath0
  libreadline7 libsqlite3-0 libssl1.0-dev libstdc++-7-dev libtinfo5 libubsan0 linux-libc-dev make manpages-dev python-all python-all-dev
  python-asn1crypto python-cffi-backend python-crypto python-cryptography python-dbus python-dev python-ipaddress python-keyring
  python-keyrings.alt python-pip python-pip-whl python-secretstorage python-setuptools python-six python-wheel python-xdg python2.7-dev
0 upgraded, 66 newly installed, 0 to remove and 0 not upgraded.
Need to get 69.1 MB of archives.
After this operation, 287 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
....(略)....
Setting up python-pip-whl (9.0.1-2.3~ubuntu1.18.04.2) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for libc-bin (2.27-3ubuntu1.3) ...

经过上述过程,pip成功安装。

希望以上说明能够对您有所帮助。