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

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?


Solution 1:

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

Solution 2:

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

Solution 3:

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.

Solution 4:

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