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?

2
  • 2
    I have installed python2.7 now (besides the default python3 of 18.04LTS). This seems to have done the trick. Youtube-dl runs now without complaints. Strange, as youtube-dl is supposed to run with Python 3.2+.
    – jacobacci
    May 20, 2018 at 7:30
  • 1
    I have looked at the issue a bit more and found the following: After a clean install of Ubuntu 18.04 LTS the command "python" yields the following: Command 'python' not found, but can be installed with: sudo apt install python3 sudo apt install python sudo apt install python-minimal You also have python3 installed, you can run 'python3' instead. So it seems, 18.04 LTS calls python3 instead of python by default. I am wondering whether this is intentional. YouTube-dl looks for python. Installing python2.7 fixes the issue
    – jacobacci
    May 21, 2018 at 6:57

11 Answers 11

51

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.

4
  • 4
    Since Ubuntu 18.04, python isn't installed by default. Only if you have no package which actually depends on Python 2, you can change the symlinks or on 20.04+ installations, install python-is-python3 which would automatically do that. But if you have some applications dependent on Python2, consider changing the shebang of the script to invoke Python 3 as the interpreter.
    – Kulfy
    Jun 1, 2020 at 17:57
  • 1
    why link to /usr/local/bin/python? why not to /usr/bin/python?
    – Yukulélé
    Nov 18, 2020 at 18:55
  • @Yukulélé, you can link anywhere, that works for you, there are many solutions to one problem. Nov 19, 2020 at 15:13
  • 1
    Ubuntu 20.04: sudo ln -s /usr/bin/python3 /usr/bin/python Mar 4, 2022 at 15:54
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

0
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
4
  • 5
    try to avoid first method which will download older version, it has bugs. Second method will be best.
    – Prvt_Yadav
    May 18, 2018 at 7:51
  • 3
    It's not bugs in youtube-dl, it's just that youtube-dl is out-of-date because Google frequently changes the rules for downloading YouTube videos faster than youtube-dl updates itself.
    – karel
    May 18, 2018 at 7:53
  • If it helps, I updated my 18.04 to 19.04 and faced this issue. For me installing via pip3 was the solution for me, snap solution didn't work.
    – Gayan
    Jul 10, 2019 at 4:07
  • pip3 install youtube-dl worked fine for me. There was no need for sudo.
    – vishless
    Aug 15, 2019 at 15:25
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.

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.

5
  • 2
    Unlike Windows, Python is an integral part of Linux OSes. Although Python 2 isn't installed by default on newer Debian based distros but still it's a bad idea to change symlinks. It's far far better to edit the shebang instead of changing symlinks if you don't want to break things that are still dependent on python2 or call the script using the specific Python version. Please have a look on last paragraph of my answer and Eliah's answer to know why python is still a symlink to python2.
    – Kulfy
    Aug 23, 2019 at 3:58
  • 2
    It's also unnecessary to change the symlinks because the youtube-dl file in the question can use either Python 2.7 or Python 3.2+ as its base interpreter.
    – karel
    Aug 23, 2019 at 4:07
  • Thank you for the feedback. I'll edit the answer to make it safer. I erroneously thought that editing the shebang wasn't doable, because when I opened it in an editor, the resulting changes made the file inoperable. But I see that it works fine with sed. That's preferable to doing messing with symlinks. Although, I think it's misleading to say that "python still is a symlink to python2", as by default it's simply a non-existent file. It's more accurate to say that it's recommended that the symlink point to python2. Aug 23, 2019 at 4:44
  • Although, I think it's misleading to say that "python still is a symlink to python2": No. I don't think so. Although it's non-existent on newer systems but still it is and should be symlink of that only. Suppose if you install python package, python 2 will be installed and python will be a symlink to python2 but the converse isn't true.
    – Kulfy
    Aug 23, 2019 at 18:54
  • "Although it's non-existent on newer systems but still it is and should be symlink of that only." I guess we'll have to agree to disagree then. If it is a symlink, it wouldn't matter which package you install, because python is a symlink to python2. But I see why it's highly recommended that the symlink be to python2 if it exists at all. Aug 26, 2019 at 4:16
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]
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
...
1
-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.

3
  • ls /usr/bin/python will only ever show /usr/bin/python, which is defined as Python 2 in PEP 394.
    – wjandrea
    Mar 5, 2019 at 1:58
  • Ignoring the problems, this seems to be effectively the same as AlexG's answer
    – wjandrea
    Mar 5, 2019 at 2:03
  • 2
    /usr/bin/python is a symlink to /usr/bin/python2
    – Kulfy
    Mar 5, 2019 at 2:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .