The “ModuleNotFoundError: No module named ‘psutil'” error occurs when you call a module you have not installed. To fix the error, let follow the article below.
ModuleNotFoundError: No module named ‘psutil’ in Python
In Python, ‘psutil‘ is a cross-platform library. The ‘psutil’ library retrieves information about the executed processes and the system’s usage. It can monitor the system, limit resource access, profile, and manage running processes. Library ‘psutil’ is supported in Python 2.6, 2.7 and 3.4 +. The error occurs when you call a module you have not installed.
from psutil import psutil for i in psutil(range(0,50)): print(i)
Traceback (most recent call last): File "./prog.py", line 1, in <module> ModuleNotFoundError: No module named 'psutil'
How to solve this error?
Install module ‘psutil’ on Python
Install the ‘psutil’ module. You can use Python pip. But note that you need to specify the exact version of Python you are using.
If you use Python 3, use the pip3 statement as follows:
pip3 install psutil
If you use Python 2, use the following pip command:
pip install psutil
Install ‘psutil’ on operating systems
I would install ‘psutil’ according to your operating system.
Install ‘psutil’ on Windows using pip
Before installing ‘psutil’, you need to create a virtual environment. Using a virtual environment helps you avoid incompatibilities between packages and break the system if you install incompatible libraries with your operating system.
Please give the virtual environment a name to be able to activate it. I named the virtual environment ‘env’ and activated it with the command:
Then you can install the ‘psutil’ module with the following command:
python3 -m pip install psutil
Install ‘psutil’ on Mac using pip
Make sure you have installed Python and pip. Just like on Windows operating systems, you also need a virtual environment. The virtual environment I still named ‘env’ and activated it with the command:
python3 -m venv env source env/bin/activate
Install ‘psutil’ in the command prompt environment:
python3 -m pip install psutil
Install module ‘psutil’ by Anaconda
Anaconda is the most popular open-source Data Science platform available on Python. Install Anaconda first, create a virtual environment, and install ‘psutil’.
To create an anaconda environment:
conda create -n psutil python=3.8
Enable the project area you will see ‘psutil’ in parentheses next to the line prompt:
source activate psutil
Finally, install ‘psutil’ with the command:
conda install -c conda-forge psutil
If you have any questions about the issue ModuleNotFoundError: No module named ‘psutil’ in Python, please leave a comment below. I will answer your questions. Thanks for reading!
My name is Jason Wilson, you can call me Jason. My major is information technology, and I am proficient in C++, Python, and Java. I hope my writings are useful to you while you study programming languages.
Name of the university: HHAU
Programming Languages: C++, Python, Java