Search code examples
python-3.xmodulevirtualenvmutagenpythoninterpreter

ModuleNotFoundError: No module named '<module.name>' - Installation error


I am building a desktop app using Python and PySimpleGUI. So far, everything works just fine. Whilst I was working at the project, I realized I need to find a way to get the duration of some mp3 files and to display it in a certain way. I discovered mutagen module that is supposed to help me in this sense, I installed, and here the problem arise:

  • It throws me ModuleNotFoundError: No module named 'mutagen'.
  • Seeing this, I started to look for the problem, but I couldn't not understand why my interpretor did not find the module even though I Installed it CORRECTLY. (as PyCharm told me)

I have tried the following:

  • I am using a local virtual environment that has installed the dependecies for the project(and some extra) and I uninstalled and installed the package 3-4 times
  • I deleted the local virtual environment and I created another one. I installed the packages again and same issue.
  • I installed a random module (scipy) and I tried to import it somewhere in the project and it thrown me same error, but this time for scipy module

My guess is that I did not configured properly my interpreter, but to be honest, I have no idea what I am doing wrong, because I followed the same steps I've been using for creating a venv with its according interpreter and for other projects, it worked just fine.

Further details:

  • Using python3.9 base .exe
  • I installed the packages in two ways: one using the pycharm IDE, and one by running pip3 install mutagen

Solution

  • You may be using a different pip that is not the one that affects the Python you are using. Instead of using

    pip install mutagen
    

    Consider using pip as a module of the Python you are using:

    python -m pip install mutagen
    

    This way you'll be sure you are working on the same Python.

    If you want to continue using plain pip, try which python and which pip to make sure they are referencing the same environment.