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?
On
Ubuntu 18.04.2 LTS
withyoutube-dl
version 2019.06.08, after creating symbolic link with following command:youtube-dl worked as usual, the error
"/usr/bin/env: ‘python’: No such file or directory"
vanished.You should be able to run youtube-dl with your version of python by doing:
Find out your python3 path by doing
which python3
youtube-dl can be installed from the default repositories in all currently supported versions of Ubuntu with this command:
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.
or
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 packagepython-is-python3
:What the package does is to interpret automatically the shebang
#!/usr/bin/env python
as apython3
shebang. In this way you can callyoutube-dl
without prepending any command and/or without creating a specific alias in~/.bashrc
file.There is also an equivalent package for deprecated
python2
, calledpython-is-python2
.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:
sudo apt install python
)sudo apt install python2
)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:
python2 /usr/local/bin/youtube-dl
orpython3 /usr/local/bin/youtube-dl
) [Personally, I havealias youtube-dl='python3 /usr/local/bin/youtube-dl'
in my .bash_aliases]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.
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.
I couldn't determine who contributed this fix, but THANKS VERY MUCH!
You just need to:
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: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
youtube-dl
to a different location. Usewhich
to find the correct address:python3
to get past this error