19.10 点用于 python 3.8

Ste*_*ton 22 python python3 pip

我已经将 python3.8 安装到 python 19.10:

 sudo apt install python3.8
Run Code Online (Sandbox Code Playgroud)

我现在想为 python 3.8 安装 pip

 python3.8 -m pip install pip
 Requirement already satisfied: pip in /usr/lib/python3/dist-packages (18.1)
Run Code Online (Sandbox Code Playgroud)

但是点 3 是3.7

 pip3 -V
 pip 18.1 from /usr/lib/python3/dist-packages/pip (python 3.7)
Run Code Online (Sandbox Code Playgroud)

因此,例如:

pip3 install pyinotify
Requirement already satisfied: pyinotify in ./.local/lib/python3.7/site-packages (0.9.6)
Run Code Online (Sandbox Code Playgroud)

尝试将 pyinotify 导入到 python3.8 脚本会引发ModuleNotFound错误

小智 15

为了确保您使用的是正确的 pip,请按如下方式使用它:

python3.8 -m pip install pyinotify
Run Code Online (Sandbox Code Playgroud)

Python 核心开发者之一 Brett Cannon 最近刚刚发表了一篇关于这个主题的博客文章:https : //snarky.ca/why-you-should-use-python-m-pip/

综上所述,您通常希望将 Python 包安装到虚拟环境中,而不是在系统 Python 中。

https://realpython.com/python-virtual-environments-a-primer/


ear*_*Lon 8

sudo apt install python3-pippython3.8-pip

让系统管理您的 Python 版本。


编辑

原来的问题是要安装pip通过python -m pip,并使用原来的海报后apt,系统包管理器,相反,他们能够得到pip正常工作。

正如评论和jugmac00的回答中所指出的,现在建议pip通过调用作为 Python 模块使用:

python -m pip install pyinotify
Run Code Online (Sandbox Code Playgroud)

如果系统上安装了多个版本的 Python 并且这不是默认版本,您可能需要指定版本:

python3.8 -m pip install pyinotify
Run Code Online (Sandbox Code Playgroud)

  • `E:无法找到包 python3.8-pip`。ubuntu 标准 repos 中有一个 `python3-pip` 包,但没有 `python3.8-pip`,在 3.8 环境中安装 `python3-pip` 会在系统上安装 Python 3.6。 (14认同)