9

我从 19.10 升级到 Ubuntu 20.04,现在我不能使用 pip。

zeno:~$ pip --version

Command 'pip' not found, but there are 18 similar ones.

Python 已安装:

zeno:~$ python3 --version
Python 3.8.2

但是如果我尝试安装 pip,我会得到:

    zeno:~/Desktop/tetris$ sudo apt install python3-pip
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    python3-pip is already the newest version (20.0.2-5ubuntu1).
    The following packages were automatically installed and are no longer required:
     dh-python elpa-async enchant gedit-plugin-zeitgeist gir1.2-mutter-5
     gnome-software-common libappstream-glib8 libapt-pkg5.90
     libboost-date-time1.67.0 libboost-iostreams1.67.0 libbrlapi0.6
     libcodec2-0.8.1 libcroco3 libdns-export1104 libdns1104 libdvdread4
     libegl1-mesa libenchant1c2a libept1.5.90 libevent-2.1-6 libexiv2-14
     libfprint0 libgeoip1 libgit2-27 libglvnd-core-dev libgnome-desktop-3-18
     libgspell-1-1 libgutenprint-common libgutenprint9 libgweather-3-15 libicu63
     libiptc0 libisc-export1100 libisc1100 libisc1105 libisl21 liblivemedia64
     liblouis17 liblwres161 libmicrodns0 libmozjs-60-0 libmutter-5-0 libmysofa0
     libnettle6 liboauth0 libperl5.28 libplymouth4 libpoppler90
     libpython3.7-minimal libqpdf21 libsnmp30 libusbmuxd4 libx11-xcb-dev
     libx265-176 libxcb-dri2-0-dev libxcb-dri3-dev libxcb-shape0-dev
     libxcb-sync-dev libxcb-xfixes0-dev libxshmfence-dev libzeitgeist-2.0-0
     perl-modules-5.28 printer-driver-gutenprint python-gobject-2
     python3-asn1crypto python3-pypdf2 python3.7-minimal ubuntu-system-service
     x11proto-composite-dev x11proto-fixes-dev
   Use 'sudo apt autoremove' to remove them.
   0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

我搞不清楚了。谢谢你的帮助

更新

我使用 venv 创建虚拟环境。当没有激活​​venv时,我可以使用pip3:

zeno:~/Desktop/tetris$ pip3 -V
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)

但是如果我激活一个venv,它就不起作用:

(.tetris) zeno:~/Desktop/tetris$ pip3
Traceback (most recent call last):
  File "/home/zeno/Desktop/tetris/.tetris/bin/pip3", line 6, in <module>
    from pip._internal import main
ModuleNotFoundError: No module named 'pip'

感谢您的建议和持续的帮助。

更新

我尝试删除 venv 并制作一个新的,但似乎我需要 pip 工作才能做到这一点:

zeno:~/Desktop/tetris$ python3 -m venv .tetris

给出:

The virtual environment was not created successfully because ensurepip is not
available.  On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.

    apt-get install python3-venv

You may need to use sudo with that command.  After installing the python3-venv
package, recreate your virtual environment.

Failing command: ['/home/zeno/Desktop/tetris/.tetris/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']
4

5 回答 5

6

有时在操作系统升级后,您需要重新安装软件包。尝试:

sudo apt install --reinstall python3-pip
于 2020-05-09T16:34:46.390 回答
0

我不得不清除 python3-venv 并重新安装它:

zeno:~$ sudo apt purge python3-venv

接着

zeno:~$ sudo apt install python3-venv

谢谢大家

于 2020-05-09T19:18:02.327 回答
0

dobairoland 在 esp-idf github(issue 4474)上给出了最适合我的解决方案,如Espressif Docs中所示:

sudo apt-get install python3 python3-pip python3-setuptools

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10

替代方案(1):起初我能够使用硬编码的第 3 方 bash 安装脚本的别名来解决这个问题pip(前面提到的安装/重新安装都不适合我) - 所以这可能是一个选项,太:

sudo apt-get install python3-pip
alias pip="pip3"

这个(诚然不太优雅的选项)可能对脚本有帮助:

if [ "$(cat /etc/os-release | grep VERSION_ID)" == 'VERSION_ID="20.04"' ]; then
 alias pip="pip3"
else 
  echo "no pip alias"
fi

替代方案 (2) 还有一个在技术上对我有用的hack,但将已弃用的软件强制到系统上可能不是一个好主意:

wget https://bootstrap.pypa.io/get-pip.py
sudo python2.7 get-pip.py
于 2020-05-23T15:32:15.593 回答
0

我发现最简单的方法就是删除虚拟环境文件夹,重新创建它并使用 pip 重新安装依赖项,现在又可以使用了:)

于 2020-11-26T09:12:21.940 回答
0

我在 ubuntu 20 上遇到了同样的问题。我用这个修复了它pip3 install --upgrade pip

于 2021-01-17T19:36:09.140 回答