AnswerBun.com

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

In Ubuntu 20.04, we get the following error:

❯ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04 LTS
Release:        20.04
Codename:       focal

❯ youtube-dl https://www.youtube.com/watch?v=b4mihzeFqGA
/usr/bin/env: ‘python’: No such file or directory

How can I fix it?

Ask Ubuntu Asked by Geoff Langenderfer on December 8, 2021

7 Answers

7 Answers

If you don't need python 2 and only need python 3, the easiest is to just

sudo apt install python-is-python3

It's actually just a symlink. The package description explains it:

In Ubuntu, all python packages use explicit python3 or python2 interpreter and do not use unversioned /usr/bin/python at all. Some third-party code is now predominantly python3 based, yet may use /usr/bin/python.

This is a convenience package which ships a symlink to point the /usr/bin/python interpreter at the current default python3. It may improve compatibility with other modern systems, whilst breaking some obsolete or 3rd-party software.

Answered by mivk on December 8, 2021

The python variable is not set and update-alternatives will not work either. Let's fix that.

Afterwards, we can decide which version python points to using $ sudo update-alternatives --config python.

Install alternatives for python 2 and 3

$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 2

$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 3

$ sudo update-alternatives --list python
/usr/bin/python2
/usr/bin/python3

Change which version to use (v3 default since higher priority)

$ sudo update-alternatives --config python

There are 2 choices for the alternative python (providing /usr/bin/python).

  Selection    Path              Priority   Status
------------------------------------------------------------
* 0            /usr/bin/python3   3         auto mode
  1            /usr/bin/python2   2         manual mode
  2            /usr/bin/python3   3         manual mode

Press <enter> to keep the current choice[*], or type selection number:

$ python --version
Python 3.8.5

Answered by Daniel on December 8, 2021

This works for ubuntu 20.04 LTS:

nano $(which youtube-dl)

and then replace the first line (the shebang line i.e. #!...) with

#!/usr/bin/python3

Answered by Matteo Paolucci on December 8, 2021

The easiest way to deal with this in Ubuntu 20.04+ is to symlink python to python3:

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

Note, however, that if you install other Python programs that rely on the older version of Python, they may not run or work correctly until you remove the symlink and install the older version of Python, or fix the programs to use Python 3. But the older Python version is no longer supported, so it would be better to use only Python programs that can run under Python 3 in the first place.

Answered by UbuntuUser on December 8, 2021

I had the exact same problem trying to install youtube-dl in ubuntu 20.04 and spent a long time trying to resolve. On the verge of giving up, I saw this from Canonical and thought it looks too simple but tried it anyway! Problem solved!

sudo snap install youtube-dl

Answered by Andy on December 8, 2021

I think python is missing on your system so,

First of all check if you have python installed . To check this simply open terminal and type python. If it shows python version and prompt then quit by typing quit()

And if python is missing then install it with this command :

sudo apt-get install python3

If that does not help, then try this command:

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

Answered by Prabhakar Prakash on December 8, 2021

In Ubuntu 20.04, python3 is the installed default. The python variable is not set:

❯ which python
python not found

We can get around this by using python3 and which:

❯ python3 $(which youtube-dl) https://www.youtube.com/watch?v=0IE-CXNs6Sw
[youtube] 0IE-CXNs6Sw: Downloading webpage

Answered by Geoff Langenderfer on December 8, 2021

Add your own answers!

Related Questions

Open a folder based on the date

3  Asked on November 21, 2021 by mrc88

 

Downsides to disabling/removing swap?

3  Asked on November 21, 2021 by gchuf

     

No Wi-fi adapter found after installing Ubuntu 20.04

0  Asked on November 19, 2021 by adesh-paul

     

KDE Plasma corrupted GNOME

0  Asked on November 19, 2021 by errornointernet

     

Cannot Boot into Windows after removing Ubuntu

2  Asked on November 19, 2021 by saad-ali-shah

       

Images not working with Glade?

1  Asked on November 19, 2021 by james-heald

       

How to get NBA 2K13 working

1  Asked on November 19, 2021

   

Trying to convert MKV to MP4 with avconv, failing

4  Asked on November 19, 2021 by collesliehaphapablap

     

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved.