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

发布于 2025-01-15 16:46:54 字数 2812 浏览 2 评论 0原文

使用 python-3.10.3-amd64.exe 安装了 Python 3.10

尝试在我的 Windows 中开始使用 python环境中,当我尝试在 bash 中执行 pip 时(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'

但它返回这个:

$ 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.

How can I start using pip in Windows Terminal?

谢谢。

Installed Python 3.10 with python-3.10.3-amd64.exe

Trying to start using python in my Windows environment, I get this in return when trying to execute pip in bash (Windows Terminal: Ubuntu profile)

$ bash > pip help

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

sudo apt install python-pip

Can't apt install package either

$ 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

It runs fine in Powershell tho.
enter image description here

Path environment variables (User and System) have been added for:

C:\python310\Scripts

C:\python310\

I've also tried making an alias for the exe in my bash profile (I've removed it)

.bashrc

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

But it returns this:

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

Seems to be an issue with sudo apt update, but when I try to update i get this

$ 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.

How can I start using pip in Windows Terminal?

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

疑心病 2025-01-22 16:46:54

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

首先,通过 alias,您尝试将 Windows Python 和 pip 与 WSL/Linux/Ubuntu 一起使用。您可以在 Stack Overflow 上找到多个问题和答案,了解为什么这不是一个好主意(即使您可以让它发挥作用)。

Ubuntu 已经在 WSL 中包含了 Python3,如果您尝试在 Ubuntu/WSL 中进行开发,则应该使用该版本。

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

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

在安装软件之前sudo apt update始终是一个好习惯,但要求您至少在 WSL/Ubuntu 上第一次执行此操作。

尝试一下,然后sudo apt install python3-pip

You likely have at least two different issues going on.

First, with the alias, you are attempting to use the Windows Python and pip with WSL/Linux/Ubuntu. You'll find multiple questions and answers here on Stack Overflow on why that isn't a good idea (even if you can get it to work).

Ubuntu already includes Python3 in WSL, and you should use that version if you are trying to develop in Ubuntu/WSL.

As for the sudo apt install python-pip failing, as noted it should be python3-pip.

As for the sudo apt install python3-pip failing, that's likely because you just installed WSL2/Ubuntu. When installed most distributions under WSL, the repository caches do not come pre-populated, in order to save on bandwidth when installing.

It's always a good practice to sudo apt update before installing software, but it's required that you do it at least the first time on WSL/Ubuntu.

Try that, then sudo apt install python3-pip.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文