为什么我不能在 Windows 终端上 运行 pip(Ubuntu 配置文件)

Why can't I run pip on Windows Terminal (Ubuntu profile)

已安装 Python 3.10 python-3.10.3-amd64.exe

尝试在我的 Windows 环境中开始使用 python,当我尝试在 bash 中执行 pip 时,我在 return 中得到了这个(Windows 终端:Ubuntu 配置文件)

$ bash > pip help

Command 'pip' not found, but can be installed with:

sudo apt install python-pip

也不能apt install package

$ bash > sudo apt install python-pip

[sudo] password for user:
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package python-pip

$ bash > sudo apt install python3-pip

[sudo] password for user:
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package python3-pip

它在 Powershell 中运行良好。

已添加路径环境变量(UserSystem):

C:\python310\Scripts

C:\python310\

我也试过在我的 bash 个人资料中为 exe 创建一个别名(我已经删除了它)

.bashrc

alias pip='C:\python310\Scripts\pip3.exe'

但它 return 是这样的:

$ bash > pip
C:\Python310\Scripts\pip3.exe: command not found

似乎是 sudo apt update 的问题,但是当我尝试更新时我得到了这个

$ bash > sudo apt update
Err:1 http://archive.ubuntu.com/ubuntu bionic InRelease
  Temporary failure resolving 'archive.ubuntu.com'
Err:2 http://security.ubuntu.com/ubuntu bionic-security InRelease
  Temporary failure resolving 'security.ubuntu.com'
Err:3 http://archive.ubuntu.com/ubuntu bionic-updates InRelease
  Temporary failure resolving 'archive.ubuntu.com'
Err:4 http://archive.ubuntu.com/ubuntu bionic-backports InRelease
  Temporary failure resolving 'archive.ubuntu.com'
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/bionic/InRelease  Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/bionic-updates/InRelease  Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/bionic-backports/InRelease  Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/bionic-security/InRelease  Temporary failure resolving 'security.ubuntu.com'
W: Some index files failed to download. They have been ignored, or old ones used instead.

如何在 Windows 终端中开始使用 pip?

谢谢。

您可能至少遇到了两个不同的问题。

首先,对于 alias,您尝试使用 Windows Python 并使用 WSL/Linux/Ubuntu 进行 pip。您会在 Stack Overflow 上找到多个问题和答案,了解为什么这不是一个好主意(即使您可以让它工作)。

Ubuntu 已在 WSL 中包含 Python3,如果您尝试在 Ubuntu/WSL.

中开发,则应使用该版本

至于 sudo apt install python-pip 失败,如前所述,应该是 python3-pip

至于 sudo apt install python3-pip 失败,这可能是因为您刚刚安装了 WSL2/Ubuntu。在 WSL 下安装大多数发行版时,存储库缓存不会出现 pre-populated,以便在安装时节省带宽。

在安装软件之前始终sudo apt update是一个好习惯,但要求您至少在第一次在 WSL/Ubuntu.

试试看,然后 sudo apt install python3-pip