-3

It looks like os.system() error.I dont know what to do next.

#!/usr/bin/env python
# -*- coding:utf-8 -*-
import re, platform, os

def init():
        cmd = {
                'centos': 'yum -y install python-devel && pip install psutil > /dev/null',
                'ubuntu': 'apt-get -y install python-dev && pip install psutil > /dev/null'
        }
        os = platform.platform().lower()

        osname = ''.join(key for key in cmd if re.findall(key,os))

        try:
                import psutil
        except ImportError:
                try:
                        os.system(cmd[osname])
                        import psutil
                except Exception as error:
                        print("Error : {}".format(error))
def collect():
        cpu = psutil.cpu_count(logical=False)
        print('cpucount: {}'.format(cpu))

if __name__ == '__main__':
        init()

os.system() function not accept string???? os.system('apt-get -y install python-dev && pip install psutil > /dev/null') ,It running when in python shell.I dont know how wrong.

[root@master python]# python test.py 
Error : 'str' object has no attribute 'system'
Arun J
  • 687
  • 4
  • 14
  • 27
  • 3
    Replace this `os = platform.platform().lower()` with `some_variable = platform.platform().lower()` – shaik moeed Jul 12 '19 at 04:34
  • *"os.system() function not accept string????"*. The problem is `os` is not module `os`, but string `os`. – Austin Jul 12 '19 at 04:36

1 Answers1

2

os = platform.platform().lower() is your culprit. Use a different name for that local variable.