How to Fix 'ModuleNotFoundError: No module named psutil' in Frappe Bench?
Error: No module named psutilResolve the common 'ModuleNotFoundError: No module named psutil' in Frappe and ERPNext by installing the psutil dependency within your bench's virtual environment using pip.
When working with the Frappe Framework, you might encounter a `ModuleNotFoundError: No module named 'psutil'`. This error typically occurs when starting the bench (`bench start`) or running other bench commands. It indicates that a required Python package, `psutil`, is missing from your bench's virtual environment. `psutil` is a cross-platform library for retrieving information on running processes and system utilization (CPU, memory, disks, network, sensors), and it is a crucial dependency for Frappe's process management.
The following commands show the standard procedure to correctly install or upgrade the `psutil` package within the isolated Python environment of your `frappe-bench`, resolving the error.
1 $ cd frappe-bench/ 2 $ source env/bin/activate 3 $ pip install --upgrade psutil 4 $ sudo pip install --upgrade psutil
Understanding This Code
What It Does
This set of commands installs the `psutil` Python package into the active Frappe bench virtual environment, resolving the 'No module named psutil' error.
When To Use
Use this solution when you see a `ModuleNotFoundError` for `psutil` while running `bench start`, `bench update`, or any other bench command.
Prerequisites
- •Access to the server terminal where your Frappe bench is installed.
- •Sudo privileges may be required for a system-wide installation attempt.
Key Concepts
Important ideas to understand in this code
Frappe Bench Virtual Environment
Each Frappe bench (`frappe-bench`) contains its own isolated Python virtual environment, typically located in the `env/` directory. It's crucial to install Python dependencies inside this specific environment to ensure they are available to Frappe and ERPNext processes. Activating it with `source env/bin/activate` is the first step before using `pip`.
Learn morepip - Python Package Installer
`pip` is the standard package manager for Python. When the virtual environment is active, running `pip install <package-name>` installs the package locally into that environment, not globally on the system. The `--upgrade` flag ensures you get the latest compatible version.
Learn moreStep-by-Step Tutorial
Follow along to understand how this code works
Navigate to Your Bench Directory
Open your terminal and change your current directory to the root of your Frappe bench. This is where the virtual environment folder (`env`) is located.
$ cd frappe-bench/Activate the Virtual Environment
Before installing any packages, you must activate the bench's virtual environment. This ensures that `pip` installs packages in the correct isolated location. Your terminal prompt will usually change to indicate that the environment is active.
$ source env/bin/activateInstall psutil using pip
With the virtual environment active, use `pip` to install the `psutil` package. The `--upgrade` flag ensures that if it's already installed but outdated, it will be updated to the latest version.
$ pip install --upgrade psutilCommon Issues & Solutions
Troubleshoot problems you might encounter