Search code examples
pythonwindows-terminal

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


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.


Solution

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