1

Why would import packageName not throw an error in the PyCharm IDE but from packageName import moduleName does throw an error? I get the error "unresolved reference moduleName" and PyCharm underlines the words "packageName" and "moduleName" in red in the source code.

This is not a duplicate question since I've tried ALL of the possible answers in this question. This question just mentions the error, which is slightly different from this issue. Unresolved reference issue in PyCharm

JustBeingHelpful
  • 18,332
  • 38
  • 160
  • 245
  • Can you post a complete example? Actually `from` is used to import a function or a piece of module and not the module name (that's what you do with `import`) so maybe that's the point: choose either `import module` or `from module import piece` – Gigioz Dec 04 '20 at 12:37
  • @Gigioz Specifically, the real code is "from redcap import Project" That's about it. Nothing complex. The packageName = "PyCap". version 1.1.2 – JustBeingHelpful Dec 04 '20 at 12:39
  • The message doesn't complain about `packageName` but `moduleName`. Are you sure `moduleName` exists? What happens if you try to do `import packageName.moduleName`? – Matthias Dec 04 '20 at 12:40
  • @Matthias "import redcap.Project" throws error "No module named Project". The word "Project" has red underlines. But if I use redcap.Project within my source code, it finds Project. – JustBeingHelpful Dec 04 '20 at 12:42
  • I don't know what to say. If I try `from redcap import Project` from the python terminal it works. Pycharm issue? Beware also that project is a module while Project is a class – Gigioz Dec 04 '20 at 12:48
  • It also works for me in Pycharm (ver 2020.2.3) – Gigioz Dec 04 '20 at 12:53
  • @Gigioz - does the Python command prompt or PyCharm not handle case sensitivity correctly? Lowercase "project" did it for me in the IDE. Python seems like such a mature language. Seems strange. – JustBeingHelpful Dec 04 '20 at 12:56
  • I think it does. Also if you make a new file and start typing the intellisense shows the correct icon for a package when you write 'project' (lowercase) while it displays the class icon if you choose Project (uppercase) – Gigioz Dec 04 '20 at 12:59
  • @Gigioz I have the PyCharm Community version 2020.1 Which version do you have? – JustBeingHelpful Dec 28 '20 at 19:07
  • Switched to Visual Studio Code. – JustBeingHelpful Jan 21 '21 at 17:10

1 Answers1

0

The Pycharm IDE has an issue with what they call "error detection" in Python.

PyCharm also helps you with errors. If you make a mistake in the code, this word will be indicated by red underlining. Hovering over this word with the mouse displays a tooltip with details.

I switched to Visual Studio Code and everything was fine. This is called source code linting, so Visual Studio Code is using the industry standard term. It appears Pylint is the extension that is handling this correctly.

from redcap import Project

import redcap.Project

Rather than having the developers of the Visual Studio Code IDE be responsible for an issue like this (if it really is one), the developer of the extension is instead. The developers of PyCharm decided to make this their responsibility because the source code linting (what they are calling error detection in Python) is built into the IDE itself, but it failed.

The community of Visual Studio Code is much larger, so I switched to Visual Studio Code.

JustBeingHelpful
  • 18,332
  • 38
  • 160
  • 245