16

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? – DK Bose 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
15

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

| improve this answer | |
  • Thanks a lot, that did the trick – jacobacci Nov 30 '19 at 8:37
10

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.

| improve this answer | |
  • 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 at 17:57
5

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 by installing the youtube-dl snap package or with pip.

sudo snap install youtube-dl # start with snap run youtube-dl  

or

sudo apt remove youtube-dl
sudo apt install python3-pip  
pip3 install --user youtube-dl
| improve this answer | |
  • 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 '19 at 4:07
  • pip3 install youtube-dl worked fine for me. There was no need for sudo. – vishnuprasanth Aug 15 '19 at 15:25
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.

| improve this answer | |
  • 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 '19 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 '19 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 '19 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 '19 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 '19 at 4:16
0

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!

| improve this answer | |
-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.

| improve this answer | |
  • ls /usr/bin/python will only ever show /usr/bin/python, which is defined as Python 2 in PEP 394. – wjandrea Mar 5 '19 at 1:58
  • Ignoring the problems, this seems to be effectively the same as AlexG's answer – wjandrea Mar 5 '19 at 2:03
  • 2
    /usr/bin/python is a symlink to /usr/bin/python2 – Kulfy Mar 5 '19 at 2:06
-2
  • 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
...
| improve this answer | |
  • 1
    Welcome new contributor! Did you intend to answer the question? This answer is incomplete or unclear. Please make an edit to fill in the gaps so that your solution is clearly stated. – Nmath May 21 at 1:28
  • What is unclear? – Geoff Langenderfer May 21 at 5:17
  • It's unclear how the "which" command answers the question. It's unclear why you posted that path in the second line. The second half of the answer is confusing and has syntax errors. Are you saying to type the second half into terminal? What is otIGRgFDMCA? There is no clear explanation of your steps, what they do, and how they solve the problem. Don't just fire off commands: explain them. – Nmath May 21 at 14:22
  • This is an issue with Ubuntu 20.04. I've made a new question for it: askubuntu.com/questions/1242139/… – Geoff Langenderfer May 21 at 14:56
  • 1
    So is this a question? Answers are for answers only. It's still unclear. Are you supposed to type that entire paragraph into the terminal. Or is this an output? You've got as much room as you need for explanation and formatting. It might help to consider writing your answer like you would write a cooking recipe. Lay out the steps in order and give some background and clarification:. If you are advocating running a command, give directions like "run the following command:". Make sure the command has a clear end and is separated from output. Otherwise it's extremely confusing. – Nmath May 21 at 15:34

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.