19

When I type python into my bash shell (Windows Subsystem for Linux) in Windows 10 Home, I get the following error message:

The program 'python' can be found in the following packages:
 * python-minimal
 * python3
Try: sudo apt install <selected package>

I've tried installing python3 but am told it's already installed and up to date.

I've tried uninstalling python-minimal but am told it's not installed (!)

Why am I seeing two "competing" packages for Python? How can I fix the conflict and configure my WSL bash to run Python 3 from python?

11
  • 1
    You could do python3, otherwise, do type -a python and it will give you an idea of what you have change. Commented Jan 30, 2018 at 14:52
  • Thanks. I need it to run from python. type -a python gives me: -bash: type: python: not found Commented Jan 30, 2018 at 14:53
  • 2
    create an alias: alias python="python3". If you're managing many versions of python, you might want to look into pyenv Commented Jan 30, 2018 at 14:56
  • 1
    python in linux world as a CLI command almost always means python2 and not python3. Make sure that you have python2 installed (sudo apt install python). DO NOT alias python to python3 - this is some bad advice! To run python3, you have to specify python3 on the CLI. Commented Jan 30, 2018 at 14:57
  • 1
    @PatrickHaugh Aliases are fine when they don't map to a legitimate command but if he had this python->python3 alias and then ran some script that had python <do_someting> in it, the shell would try to invoke python3 when the writer of that script was explicitly intending to run <do_something> on python2 so it would likely break. That plus the fact that most Linux bin commands are actually python scripts, this would cause all kinds of funky problems. Commented Jan 30, 2018 at 15:28

3 Answers 3

18

If you're running Ubuntu 20 under WSL, there is a new package called python-is-python3:

cameron@Nook:/mnt/c/Users/camer$ sudo apt install python-is-python3
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  python-is-python3
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 2364 B of archives.
After this operation, 10.2 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu focal/main amd64 python-is-python3 all 3.8.2-4 [2364 B]
Fetched 2364 B in 0s (7208 B/s)
Selecting previously unselected package python-is-python3.
(Reading database ... 33571 files and directories currently installed.)
Preparing to unpack .../python-is-python3_3.8.2-4_all.deb ...
Unpacking python-is-python3 (3.8.2-4) ...
Setting up python-is-python3 (3.8.2-4) ...
cameron@Nook:/mnt/c/Users/camer$ python --version
Python 3.8.10

Alternatively, you could use update-alternatives:

sudo update-alternatives --install /usr/bin/python python $(readlink -f $(which python3)) 3
Sign up to request clarification or add additional context in comments.

Comments

7

python in linux world as a CLI command almost always means python2 and not python3. Make sure that you have python2 installed (sudo apt install python).

DO NOT alias python to python3 - this is some bad advice!

To run python3, you have to specify python3 on the CLI.

3 Comments

Not an answer and not a good advice or bad, it is just a preference of developer, this should not be an answer at all.
No. python2 is dead. python should run Python 3.x.
This was perfectly good advice in 2018, though.
-1

If your script may works with python3, alias is the simple way:

sudo ln -s /usr/bin/python3 /usr/bin/python

1 Comment

No. Don't mess with /usr/bin. If you want this, put the symlink in /usr/local/bin/python

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.