13

Lately I've noticed that we've got a lot of questions about ModuleNotFoundErrors. As in, 3330 questions a lot.

Most of these questions seem to have the root cause of the module not being installed or being installed incorrectly. Just a couple random examples:

I would suggest that we decide on one of these questions (or create a new one) and close all the ModuleNotFoundError questions with the same root cause as a duplicate of the question we decide on.

Thoughts? Discussion? Waffles?

36
  • 14
    Yes, the problem is caused by the module not being found, that's clear. The issue with closing as a duplicate is that the users are expecting the module to be found, and are confused as to why it isn't. This will usually boil down to the user importing the wrong thing, and the specific mistake is going to differ. A canonical for this would be so useless it would border on nonsense. Closing the questions as duplicates of the canonical without any other explanation would be so absolutely frustrating with no positive outcome for anyone involved. How would this make the internet a better place?
    – user4639281
    Commented May 9, 2019 at 21:55
  • 4
    @TinyGiant it would make the internet a better place by keeping all answers in one place so they can be more easily updated, and by directing users to an exhaustive answer that probably outlines why they are getting the error. Whereas currently, the majority of these questions are unanswered with a few relatively unhelpful comments.
    – Picachieu
    Commented May 9, 2019 at 21:58
  • 2
    But an answer that is general enough to apply to all situations would only say "You're receiving this error because the module was not found", and that would be completely useless and not worth the bits that it would be comprised of. Otherwise the specific answer is going to be different for every question, making the questions not duplicates.
    – user4639281
    Commented May 9, 2019 at 22:01
  • 3
    @TinyGiant no, an answer general enough to apply to all situations would say "You're receiving this error because the module was not found. Depending on the situation, you can fix it by ..." My whole point is that the answer will not be different for every question, because most of them are caused by the same thing. The ones causes by something different can be left open.
    – Picachieu
    Commented May 9, 2019 at 22:03
  • 6
    We need a canonical for the "how to find the canonical" meta question. "Try the chat room" is the usual answer. Commented May 9, 2019 at 22:07
  • 6
    @TinyGiant I think you're misunderstanding my proposal. I'm not proposing that we make one question related to every possible case of a ModuleNotFoundError. I'm proposing that we make one canonical for ModuleNotFoundErrors caused by a module not being installed or being installed correctly. A canonical answer for this wouldn't really be that long.
    – Picachieu
    Commented May 9, 2019 at 22:09
  • 3
    @TinyGiant I see people quickly finding solutions to their problems through the marking-as-duplicate process.
    – Picachieu
    Commented May 9, 2019 at 22:27
  • 3
    @TinyGiant simple solution: make it clear in the canonical's title that it only provides a solution when the problem is because the module isn't installed correctly.
    – Picachieu
    Commented May 9, 2019 at 22:31
  • 2
    @TinyGiant it will solve the problem you just mentioned. It will be clearer that it is not a canonical for all ModuleNotFoundError problems, and users will read through it more carefully before closing.
    – Picachieu
    Commented May 9, 2019 at 22:51
  • 5
    canonicals are good. common easily researched questions are bad. a canonical we can close these easily researched questions with that teaches the user how to debug/resolve the very common beginner issue with is a win-win solution.
    – Kevin B
    Commented May 9, 2019 at 23:03
  • 5
    Fortunately, dupe closure can be reversed, and if someone is abusing it, that can be reported. the fact that it will eventually be abused isn't a reason to not have it.
    – Kevin B
    Commented May 9, 2019 at 23:53
  • 2
    They don't have the same root cause, they have the same error, all with different root causes.
    – user4639281
    Commented May 10, 2019 at 0:06
  • 2
    @TinyGiant no, lots of them have the same cause: a module not being installed or being installed correctly. I'm not proposing a canonical for other ModuleNotFoundError questions.
    – Picachieu
    Commented May 10, 2019 at 0:07
  • 2
    @TinyGiant we've already been through this: yes, there will be people who abuse the system. But that doesn't mean it's a bad system. This form of abuse is especially easy to dig up and also very easy to revert.
    – Picachieu
    Commented May 10, 2019 at 0:10
  • 3
    @TinyGiant there is a problem: there are lots of questions with the same error and same root cause, and we don't have a clear question to close them as a duplicate of. Creating a canonical would solve that problem.
    – Picachieu
    Commented May 10, 2019 at 0:17

1 Answer 1

3

I noticed the same! And I've found that there are several, similar but subtly different causes for this problems. In the most basic case, a user just forgot to install a package using pip install <package>. However, in many other cases the user did execute command, but in another Python environment, so that they still got the ModuleNotFoundError when executing their code. Sometimes it depends on how they execute the code.

I've written quite a comprehensive answer for one of these questions, trying to explain everything needed to know to understand why this happens and how to solve it. Since then I try to direct persons with the same question to that answer in the hope that this answer would solve this problem "once and for all" ;-) Otherwise the same "interview" (did you try this? did you try that? how did you install it? how did you run it? etc.) has to be repeated everytime...

My answer focuses on Windows, but some of it is true for other operating systems as well. I still want to extend my answer with some info about virtual environments, but I think it is a useful answer already. Suggestions/improvements are welcome of course. Please leave a comment and I'll try to improve it if necessary.

What do you think? Could this be a canonical answer for (many, probably not all) ModuleNotFoundError-questions?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .