0

I am enrolled in a machine learning competition and, for some reason, the submission is not a CSV file, but rather the code in Python. In order to make it run, they asked the participants to create another file called install.py to automatically install all the packages used.

I need to install multiple packages (keras, numpy, etc.).

For each package, I have to use the command os.system. I have no idea what it does, and this is the only information that I have.

Yes, this type of question was asked before, but not with several packages and this specific os.system line.

3 Answers3

0

I don't know if this might work for your specific issues. Give it a go.

import os

packages = ["keras","sklearn"] #etc

for package in packages:
    os.system("pip install "+ package) #installs particular package
GILO
  • 1,306
  • 8
  • 24
0

The way I recommend doing this is to import pip as a module, as follows: (untested)

import pip

def install(package):
    if hasattr(pip, 'main'):
        pip.main(['install', package])
    else:
        pip._internal.main(['install', package])

packages = [] #Add your packages as strings
for package in packages:
    install(package)

I used this question for most of the code.

Zombie_Pigdragon
  • 107
  • 3
  • 11
0

You could create a requirements.txt file with all of your package requirements.

import os

os.system("pip install -r requirements.txt")
Jack Moody
  • 1,345
  • 2
  • 14
  • 33