8

In Ubuntu 20.04, we get the following error:

❯ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04 LTS
Release:        20.04
Codename:       focal

❯ youtube-dl https://www.youtube.com/watch?v=b4mihzeFqGA
/usr/bin/env: ‘python’: No such file or directory

How can I fix it?

8 Answers 8

12

In Ubuntu 20.04, python3 is the installed default. The python variable is not set:

❯ which python
python not found

We can get around this by using python3 and which:

❯ python3 $(which youtube-dl) https://www.youtube.com/watch?v=0IE-CXNs6Sw
[youtube] 0IE-CXNs6Sw: Downloading webpage
8

I think python is missing on your system so,

First of all check if you have python installed . To check this simply open terminal and type python. If it shows python version and prompt then quit by typing quit()

And if python is missing then install it with this command :

sudo apt-get install python3

If that does not help, then try this command:

sudo update-alternatives --install  /usr/bin/python python /usr/bin/python3 1000
1
  • 2
    Do this : sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 1000 May 21, 2020 at 15:24
6

The easiest way to deal with this in Ubuntu 20.04+ is to symlink python to python3:

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

Note, however, that if you install other Python programs that rely on the older version of Python, they may not run or work correctly until you remove the symlink and install the older version of Python, or fix the programs to use Python 3. But the older Python version is no longer supported, so it would be better to use only Python programs that can run under Python 3 in the first place.

1
  • 2
    or add alias python=python3 to your bashrc Apr 17, 2021 at 14:02
3

I had the exact same problem trying to install youtube-dl in ubuntu 20.04 and spent a long time trying to resolve. On the verge of giving up, I saw this from Canonical and thought it looks too simple but tried it anyway! Problem solved!

sudo snap install youtube-dl

2
  • The nice thing about this solution is that after, you can still use the previous syntax <youtube-dl youtube.com/watch?v=1234567890>
    – John
    Jul 27, 2020 at 14:21
  • This didn't work for me under Linux Mint 20.1 Ulyssa. I get the OPs message: /usr/bin/env: «python»: No existe el archivo o el directorio
    – Scooby-2
    Sep 28, 2021 at 22:01
2

This works for ubuntu 20.04 LTS:

nano $(which youtube-dl)

and then replace the first line (the shebang line i.e. #!...) with

#!/usr/bin/python3
1
1

The python variable is not set and update-alternatives will not work either. Let's fix that.

Afterwards, we can decide which version python points to using $ sudo update-alternatives --config python.

Install alternatives for python 2 and 3

$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 2

$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 3

$ sudo update-alternatives --list python
/usr/bin/python2
/usr/bin/python3

Change which version to use (v3 default since higher priority)

$ sudo update-alternatives --config python

There are 2 choices for the alternative python (providing /usr/bin/python).

  Selection    Path              Priority   Status
------------------------------------------------------------
* 0            /usr/bin/python3   3         auto mode
  1            /usr/bin/python2   2         manual mode
  2            /usr/bin/python3   3         manual mode

Press <enter> to keep the current choice[*], or type selection number:

$ python --version
Python 3.8.5
1

If you don't need python 2 and only need python 3, the easiest is to just

sudo apt install python-is-python3

It's actually just a symlink. The package description explains it:

In Ubuntu, all python packages use explicit python3 or python2 interpreter and do not use unversioned /usr/bin/python at all. Some third-party code is now predominantly python3 based, yet may use /usr/bin/python.

This is a convenience package which ships a symlink to point the /usr/bin/python interpreter at the current default python3. It may improve compatibility with other modern systems, whilst breaking some obsolete or 3rd-party software.

0

#Debian 11 #Install

sudo wget https://yt-dl.org/downloads/latest/youtube-dl -O /usr/bin/youtube-d

youtube-dl -U

/usr/bin/env: ‘python’: No such file or directory

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

youtube-dl -U

youtube-dl is up-to-date (2021.12.17)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.