40

I have done a clean install of 18.04 LTS. I then installed youtube-dl using

sudo wget https://yt-dl.org/downloads/latest/youtube-dl -O /usr/local/bin/youtube-dl
sudo chmod a+rx /usr/local/bin/youtube-dl

When I try to use youtube-dl, I get the following error message:

rudolffischer@HP8770w:~$ youtube-dl -U
/usr/bin/env: ‘python’: No such file or directory

Python 3 seems to be installed

rudolffischer@HP8770w:~$ python3
Python 3.6.5 (default, Apr  1 2018, 05:46:30) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

Why?

Lorenz Keel
  • 9,511
jacobacci
  • 531

11 Answers11

53

On Ubuntu 18.04.2 LTS with youtube-dl version 2019.06.08, after creating symbolic link with following command:

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

youtube-dl worked as usual, the error "/usr/bin/env: ‘python’: No such file or directory" vanished.

ThrivingWithLinux
  • 1,072
  • 9
  • 12
22

You should be able to run youtube-dl with your version of python by doing:

/your/path/python3 /usr/local/bin/youtube-dl

Find out your python3 path by doing which python3

Alex
  • 321
11

youtube-dl can be installed from the default repositories in all currently supported versions of Ubuntu with this command:

sudo apt install youtube-dl  

youtube-dl's self-update mechanism is disabled on Debian-based operating systems except for the youtube-dl snap package which is automatically updated. You can also update youtube-dl to the latest version by installing youtube-dl with pip.

sudo snap install youtube-dl # launch it with snap run youtube-dl

or

sudo apt remove youtube-dl
sudo apt install python3-pip  
python3 -m pip install youtube-dl
karel
  • 122,292
  • 133
  • 301
  • 332
10

Another possible solution has been suggested in a comment by Kulfy, it deserves more visibility.

Starting from Ubuntu 20.04 (where the default version of python is python3) you can install the package python-is-python3:

sudo apt install python-is-python3

What the package does is to interpret automatically the shebang #!/usr/bin/env python as a python3 shebang. In this way you can call youtube-dl without prepending any command and/or without creating a specific alias in ~/.bashrc file.

There is also an equivalent package for deprecated python2, called python-is-python2.

Zanna
  • 72,312
Lorenz Keel
  • 9,511
1

The head of the youtube-dl script has #!/usr/bin/env python, meaning that it uses the "python" command.

Per https://www.python.org/dev/peps/pep-0394/ Distributions can choose include the python command linked to python2 or python3, not include the command at all, or allow the user/admin to configure it.

In debian-based installs, there are 3 main python packages:

  • python (sudo apt install python)
  • python2 (sudo apt install python2)
  • python3 (sudo apt install python3)

The "python" package installs python version 2 and includes the "python" command (symlink /usr/bin/python -> /usr/bin/python2).

The "python2" and "python3" packages do not provide the "python" command. This means that calling "python" from the CLI or a script will result in a "command not found" error.

If you're using these, you have to either:

  • call the script using whichever version you like (python2 /usr/local/bin/youtube-dl or python3 /usr/local/bin/youtube-dl) [Personally, I have alias youtube-dl='python3 /usr/local/bin/youtube-dl' in my .bash_aliases]
  • edit the youtube-dl script to use python2 or python3 (sudo sed -i '1s/python/python2/' /usr/local/bin/youtube-dl) or (sudo sed -i '1s/python/python3/' /usr/local/bin/youtube-dl)

In the above, I prefer using the aliasing option since you leave the file alone and don't have to edit it every time the file gets updated

It's also possible to fix it by creating a symlink for /usr/bin/python, but that is not adviseable.

1

I'd like to report that the script mod using sed (below) fixed the "/usr/bin/env: ‘python’: No such file or directory" error in my current snap installation of youtube-dl.

sudo sed -i '1s/python/python3/' /usr/local/bin/youtube-dl

$ snap list youtube-dl
Name        Version                Rev   Tracking  Publisher  Notes
youtube-dl  2020.02.16+gitbee6451  2682  edge      joeborg    -

$ lsb_release -d ; uname -rp ; gnome-shell --version ; echo $XDG_SESSION_TYPE
Description:    Ubuntu 19.10
5.3.0-40-generic x86_64
GNOME Shell 3.34.1
wayland

I couldn't determine who contributed this fix, but THANKS VERY MUCH!

0

You just need to:

python3 youtube-dl {url}
0

For those answers adding the full path to both python3 and youtube-dl commands: The problem is not that python3 can't be found in PATH, the problem is that youtube-dl script shebang line is #!/usr/bin/env python. The shortest solution should be:

python3 `which youtube-dl` [URL]
manuq
  • 111
0

Adding an alternative worked for me:

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 1

https://linuxconfig.org/ubuntu-20-04-python-version-switch-manager

-1
  • You may have downloaded youtube-dl to a different location. Use which to find the correct address:
$ which youtube-dl
/home/linuxbrew/.linuxbrew/bin/youtube-dl
  • You can use python3 to get past this error
$ python3 $(which youtube-dl) https://www.youtube.com/watch?v=0IE-CXNs6Sw
[youtube] 0IE-CXNs6Sw: Downloading webpage
...
-2

this solution to youtube-dl error works for Ubuntu 18.04.02 LTS.
(The date when I wrote this is Mar.04.2019 so please check version).

This is the way, when using youtube-dl, I solved the following error message :

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

  1. cd /usr/bin
  2. ls python

This should show you what python version you have. If your python version is 3 or above just go to step 4. if your version is below python 3 go to step3.

  1. sudo apt install python3
  2. /usr/bin/python3.6 /usr/local/bin/youtube-dl ( your youtube video hyper link).

( in my case I had python 3.6 located in /use/bin/(whatever python version). Obviously, you have to adjust for whatever python version you have).

this should work for that stupid /usr/bin/env python error on youtube-dl.

NIMISHAN
  • 1,625
  • 4
  • 20
  • 28
tim
  • 11