I am working on MacOS BigSur/Version 11.5.2/ Python 3.9.5.
So i keep getting this import mistake when i try to run my python code:
*import subprocess
import psutil
import schedule
import time
import csv
import sys
import httpx
import asyncio
import json
csv_headers = ["company_id", "dep_id", "host_id", "cpu_count", "cpu_load", "ram_total", "ram_used", "diskspace_total", "diskspace_used", "diskspace_free", "operations_read", "operations_write", "timeresponse_min_ms", "timeresponse_avg_ms", "timeresponse_max_ms"]
def get_statistics_windows():
statistics = {}
statistics['company_id'] = "comp301"
statistics['dep_id'] = "dep301"
statistics['host_id'] = "host301"
# Get Physical and Logical CPU Count
physical_and_logical_cpu_count = psutil.cpu_count()
statistics['cpu_count'] = physical_and_logical_cpu_count
# Get CPU load in percentage (system wide)
statistics['cpu_load'] = psutil.cpu_percent(interval=1)
# Memory usage
statistics['ram_total'] = round(psutil.virtual_memory().total / 1024 ** 3, 2)
statistics['ram_used'] = round(psutil.virtual_memory().used / 1024 ** 3, 2)
#Disk Usage
statistics['diskspace_total'] = round(psutil.disk_usage('/').total / 1024 ** 3, 2)
statistics['diskspace_used'] = round(psutil.disk_usage('/').used / 1024 ** 3, 2)
statistics['diskspace_free'] = round(psutil.disk_usage('/').free / 1024 ** 3, 2)
statistics['operations_read'] = psutil.disk_io_counters().read_count # read bytes
statistics['operations_write'] = psutil.disk_io_counters().write_count # written bytes
# Network latency
ping_result = subprocess.run(['ping', '-i 5', '-c 5', 'google.com'], stdout=subprocess.PIPE).stdout.decode(
'utf-8').split('\n')
min_response_time, max_response_time, avg_response_time = ping_result[0].split('=')[-1], ping_result[1].split('=')[-1], ping_result[2].split('=')[-1]
statistics['timeresponse_min_ms'] = min_response_time.replace('ms', '').strip()
statistics['timeresponse_avg_ms'] = avg_response_time.replace('ms', '').strip()
statistics['timeresponse_max_ms'] = max_response_time.replace('ms', '').strip()
return statistics*
There is 100% no mistake in the code because i was asked to test it, so it works on other machines. I tried to do
pip install psutil
and got - "Successfully installed psutil-5.8.0" response but in my Visual Studio i still keep getting this error.
I also used a command sudo pip install --upgrade psutil which successfully update the package but still doesnt seem to work in my Visual Studio
Does anybody know how to make my Visual Studio see this package, so my code could run?
Thanks in advance!