1

I want to automate process of installing dependencies on linux but whenever I run my commands nothing happens.

CODE:

commands_to_run = ["sudo apt-get update && sudo apt-get upgrade",
                   "sudo apt-get install build-essential cmake pkg-config",
                   "sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev",
                   "sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev",
                   "sudo apt-get install libxvidcore-dev libx264-dev",
                   "sudo apt-get install libgtk2.0-dev libgtk-3-dev",
                   "sudo apt-get install libatlas-base-dev gfortran",
                   "sudo apt-get install python2.7-dev python3-dev"]

import subprocess

for command in commands_to_run:
    subprocess.call(command, shell=True)

I tried many different options but nothing works. I refuse to believe that you can't automate dependency installation on Linux.

EDIT: It seems that it works but it doesn't do anything. When I want to run this again but through terminal it tells me that dependency is not installed and asks me if I want to install it (y/n).

Hsin
  • 307
  • 5
  • 15
  • 2
    i run this and it works .. – Druta Ruslan May 19 '18 at 11:05
  • 1
    Why doesn't it work? It looks fine. – Nishant May 19 '18 at 11:08
  • 2
    Please read https://stackoverflow.com/help/mcve "It doesn't work" is not a problem statement. – Adrian W May 19 '18 at 11:12
  • Because `sudo` forces you to input a password. https://stackoverflow.com/questions/25215604/use-sudo-without-password-inside-a-script – Xantium May 19 '18 at 11:35
  • 1
    A minimal, verifiable example would be `commands_to_run = ["ls -l", "pwd "]`. You should see the output of the two commands. That investigation should bring you closer to the source of your problem. If that works, than probably `sudo` is problem, as suggested by @Simon. You can make an entry in `/etc/sudoers.d` to the rescue. – Adrian W May 19 '18 at 11:44
  • @AdrianW I think problem is that there is y/n prompt in sudo apt-get at one point and I don't know how to type "y" if you can't do this right away at the start of the command – Hsin May 19 '18 at 11:50
  • *"I refuse to believe that you can't automate dependency installation on Linux..."* - Lol. I have a GitHub with scripts do it because it is not possible to automate. Dependencies are managed manually. Also see [Noloader | BuildScripts](https://github.com/noloader/Build-Scripts). – jww May 19 '18 at 14:34
  • @jww Joke's on you because I've done it :) you only need to add -y (where necessary) at the end of command. Thanks again Adrian W for tip. – Hsin May 20 '18 at 07:46
  • @Hsin - Try it on AIX, Fedora 1, OS 10.8, Solaris 10 or Ubuntu 8 and let me know how it goes for you. – jww May 20 '18 at 12:44
  • It doesn't matter as long as it supports python. I won't respond anymore as discussion with you is off topic. – Hsin May 20 '18 at 13:53

1 Answers1

1

apt-get supports a -y flag which automatically answers any question with yes. See https://linux.die.net/man/8/apt-get. That should solve your problem.

Adrian W
  • 4,563
  • 11
  • 38
  • 52