Mega Players
Mega Players

Reputation: 35

Why can't I use the pip3 that comes from Windows in WSL2 Ubuntu

alban@DESKTOP-P7H1H2P:/mnt/c/Users/alban$ pip3
Command 'pip3' not found, but can be installed with:
sudo apt install python3-pip

But when I do the same with CMD or PowerShell:

PS C:\Users\alban> pip3

Usage:
  pip3 <command> [options]

It is there, so why can't it use the same pip? Is there a way to point WSL to that installation?

Upvotes: 2

Views: 2974

Answers (2)

NotTheDr01ds
NotTheDr01ds

Reputation: 20629

Old question that got bumped today with a late answer, but it needs some more explanation for anyone who comes across this question.

First, WSL does several things that allow you to run Windows executables from the Linux command-line:

  • By default, it automatically appends the Windows path to the Linux path.
  • By default, it allows you to run Windows executables, but you do need to specify the extension, since Linux doesn't really understand the "concept" of extensions, at least not for executables.

Note that both of these features can be disabled through /etc/wsl.conf, but it's unlikely that you should ever need to do this.

So, as the other answer says, if you can run pip3 from within CMD or PowerShell, you should be able to run pip3.exe from inside WSL/Linux.

But that shouldn't be the end of the discussion. Just because something can be done doesn't mean it's a good idea ;-).

The Windows versions of Python and pip are designed, naturally, for Windows. They understand Windows path formats, Windows processes, etc. If you try to pass it a Linux path (which is natural within WSL), it's not going to work.

is there a way to point at that installation

So yes, while you can point WSL to the Windows Python/pip installation, it's not recommended. It's better to install the Linux version of pip3 (sudo apt install python3-pip).

Upvotes: 2

Thomas Lecarpentier
Thomas Lecarpentier

Reputation: 64

To use pip3 on WSL-2 you need to force using the ".exe" binary on your command line:

pip            pip.exe     pip3         pip3.8         pip3.8.exe     pip3.exe
^ not work     ^ work      ^ not work   ^ not work     ^ work         ^ work

You will also need to install Python under Windows beforehand.

Upvotes: 4

Related Questions