I am still fairly new to IT so please bear with me. I am currently attempting to run a script from the Ubuntu 18.04 LTS on my Windows laptop. the script is:
#!/usr/bin/env python3
import psutil
def check_cpu_usage(percent):
usage = psutil.cpu_percent()
return usage < percent
if not check_cpu_usage(75):
print("ERROR! CPU is overloaded!")
else:
print("Everything Ok")
When I run the script in Ubuntu is get the error message:
Traceback (most recent call last):
File "./cpu_usage.py", line 3, in <module>
import psutil
ModuleNotFoundError: No module named 'psutil'
However, when I run the script in the windows command prompt it works as expected. Also when I change the shebang line to #!/usr/bin/env python2 the script runs as expected in the Ubuntu 18.04 LTS terminal.
My question is this: How do I install psutil directly to my most current version of Python, or is there something I am completely missing for the script to work?
Try to install psutil
with pip for your python3 interpreter.
pip3 install -U psutil
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.