5

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?

  • What do you see with apt list --installed | grep -i python2? – Justice for Monica May 18 '18 at 7:23
  • 1
    What about python 2? (python) – fosslinux May 18 '18 at 7:26
  • 1
    @ubashu Python 2.x is not installed by default in Ubuntu 18.04. The default Python version in Ubuntu 18.04 is Python 3.6 like the code block in the question says. This same Python 3.x package is a dependency of youtube-dl in Ubuntu 18.04. – karel May 18 '18 at 7:36
  • 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 '18 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 '18 at 6:57
4

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

python3 /usr/local/bin/youtube-dl

Find out your python3 path by doing which python3

  • Thanks a lot, that did the trick – jacobacci Nov 30 at 8:37
4

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 that is installed by this command should work fine without needing to be updated, except by the usual default software updates.

youtube-dl's self-update mechanism is disabled on Debian-based operating systems. You can update to the latest version of youtube-dl either with pip or by installing the youtube-dl snap package.

sudo apt remove youtube-dl
sudo apt install python3-pip  
pip3 install --user youtube-dl  

or

sudo snap install youtube-dl # start with snap run youtube-dl
  • 4
    try to avoid first method which will download older version, it has bugs. Second method will be best. – Prvt_Yadav May 18 '18 at 7:51
  • 1
    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 '18 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 at 4:07
  • pip3 install youtube-dl worked fine for me. There was no need for sudo. – vishnuprasanth Aug 15 at 15:25
2

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.

  • 3
    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 at 4:02
0

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.

  • 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 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 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. – Chris Slycord Aug 23 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 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. – Chris Slycord Aug 26 at 4:16
-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.

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

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.