为什么我不能在 Windows 终端上运行 pip(Ubuntu 配置文件)
使用 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
已添加路径环境变量(User
和 System
):
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.
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能至少遇到两个不同的问题。
首先,通过
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 bepython3-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
.