最近 讓GHAT gpt給我寫了一個py讀取電腦硬體的代碼,需要安裝Python,現在給Python的安裝方法共享出來:
1、找到下載下傳網站:
下載下傳位址:https://www.python.org/downloads/release/python-3113/
我選的是:Windows installer (64-bit),這個和你的電腦版本有一點關系,我的是64位的。
2.輕按兩下安裝程式:
3、開始出現安裝步驟:
翻譯如下:(翻譯隻能湊合着看)
進階選項我基本是全選的狀态,最後一個安裝位置不能選,其實也無所謂了
4、開始使用python了
win+R
輸入cmd
輸入 cmd 點選确定或則回車 然後輸入 tython,如果出現 以下代碼,就證明 PY 環境正常了。
總結:安裝很簡單,如果你還不知道怎麼使用,請再評論區回報哦!
上傳一份GPT寫的讀取電腦硬體資訊的代碼:(未測試的)歡迎你的測試,
import platform
import psutil
import socket
import uuid
def get_system_info():
system = platform.uname()
processor = platform.processor()
os_version = platform.system() + ' ' + platform.release()
return {
'system': system,
'processor': processor,
'os_version': os_version
}
def get_cpu_info():
cpu_count = psutil.cpu_count()
cpu_load = psutil.cpu_percent(interval=1, percpu=True)
return {
'cpu_count': cpu_count,
'cpu_load': cpu_load
}
def get_memory_info():
mem = psutil.virtual_memory()
return {
'total': mem.total,
'available': mem.available,
'used': mem.used,
'percent': mem.percent
}
def get_disk_info():
partitions = psutil.disk_partitions()
disks = []
for partition in partitions:
disk = {}
try:
usage = psutil.disk_usage(partition.mountpoint)
disk['device'] = partition.device
disk['mountpoint'] = partition.mountpoint
disk['filesystem'] = partition.fstype
disk['total'] = usage.total
disk['used'] = usage.used
disk['free'] = usage.free
disk['percent'] = usage.percent
disks.append(disks)
return disks
def get_network_info():
hostname = socket.gethostname()
ip_address = socket.gethostbyname(hostname)
mac_address = ':'.join(['{:02x}'.format((uuid.getnode() >> ele) & 0xff)
for ele in range(0, 8 * 6, 8)][::-1])
return {
'hostname': hostname,
'ip_address': ip_address,
'mac_address': mac_address
}
if __name__ == '__main__':
print('System information:')
for key, value in get_system_info().items():
print('- {}: {}'.format(key, value))
print('')
print('CPU information:')
for key, value in get_cpu_info().items():
print('- {}: {}'.format(key, value))
print('')
print('Memory information:')
for key, value in get_memory_info().items():
print('- {}: {}'.format(key, value))
print('')
print('Disk information:')
for disk in get_disk_info():
for key, value in disk.items():
print('- {}: {}'.format(key, value))
print('')
print('Network information:')
for key, value in get_network_info().items():
print('- {}: {}'.format(key, value))
print('')