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

MacGyver
  • 17,477
  • 37
  • 155
  • 239
  • 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 – MacGyver 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. – MacGyver 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. – MacGyver 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? – MacGyver Dec 28 '20 at 19:07
  • Switched to Visual Studio Code. – MacGyver Jan 21 '21 at 17:10

0 Answers0