The error ModuleNotFoundError: No module named 'moviepy.editor' typically occurs when the moviepy library is installed but not properly recognized in your environment. Since you mentioned you have moviepy version 2.1.2 installed, the issue might be related to how the library is imported or installed.
Let’s troubleshoot and resolve the issue step by step:
1. Verify Installation
Ensure that moviepy is installed in the correct Python environment. Run the following command in your terminal or command prompt:
pip show moviepy
This will display details about the moviepy installation, including the version and installation path. If it’s not installed, install it using:
pip install moviepy
If you’re using Python 3, you may need to use pip3 instead:
pip3 install moviepy
2. Check Python Environment
If you’re using a virtual environment, ensure that the environment is activated before running the script. For example:
-
On Windows:
.\venv\Scripts\activate
-
On macOS/Linux:
source venv/bin/activate
Then, reinstall moviepy in the virtual environment:
pip install moviepy
3. Correct Import Statement
The correct way to import moviepy is:
from moviepy.editor import VideoClip
Ensure that this line is present in your script. If you’re still encountering the error, try importing moviepy directly in a Python shell to test:
import moviepy.editor
If this works, the issue might be specific to your script or environment.
4. Reinstall MoviePy
If the issue persists, uninstall and reinstall moviepy to ensure a clean installation:
pip uninstall moviepy
pip install moviepy
5. Check for Conflicting Installations
Sometimes, multiple Python installations on your system can cause conflicts. Ensure that is installed in the same Python environment where you’re running the script. You can check the Python version and path using: