• Register
2 votes
1k views

Problem:

I am new in python programming an I am using Jet Brains Pycharm IDE.
In pycharm I have program organized like:
 Sources
   |--__init__.py
   |--Additions
      |--__init__.py
      |--Add.py
   |--Collaboration
      |--__init__.py
      |--Colab.py
   |--Views
      |--__init__.py
      |--views.py
   |--Model
      |--__init__.py
      |--Models.py

But there is an warning that always appear:

Cannot find reference 'Add' in __init__.py

Why is this warning always appear please help

10 7 2
6,060 points

Please log in or register to answer this question.

2 Answers

2 votes

Answer:

Looks like this issue will pop up again if one use a remote environment in PyCharm, because PyCharm somehow forget to sync these *.pyi files to the local remote storage.
Solution: Manually mapping the local remote storage to the remote path, then sync *.pyifiles to local would solve these problem.

Plz spread this tip so nobody suffer from these annoying falsify inspection warning again

PyCharm has its share of small bugs like this, but in my opinion its benefits far outweigh its drawbacks. If you'd like to try another good IDE, there's also Spyder/Spyderlib.

You can locate the path to local storage at the Project View -> External Libraries -> Your Environment -> Remote Libraries, then right click and choose "Copy Path"

Please look out if there is any update in you IDE.

If this helps you let me know.

 

 

11 6 4
34,950 points
0 votes

Solution:

I guess this is a bug in pycharm. PyCharm exhibits to be expecting the referenced module to be added in an __all__ = [] statement.

For precise coding etiquette, must you include the __all__ statement from your modules? this is really the question we hear young Spock answering while he was being tested, to which he responded: "It is morally praiseworthy however not morally obligatory."

To get around it, you can easily disable that  (highly helpfulful) inspection globally, or inhibit it for the earmarked function or statement.

To do so:

  • Place the caret over the erroring text ('choice', from your example above)

  • Educate the intention menu (alt-enter by default, mine is set to alt-backspace)

  • Press the right arrow to open the submenu, and choose the relevant action

PyCharm has its share of small bugs like this, however in my view its benefits far outweigh its drawbacks. In case you'd like to attempt another good IDE, there's also Spyder/Spyderlib.

I know this is quite a bit after you asked your question, however I hope this helps.

Edited: Generally, I conceived that this was earmarked to checking __all__, however it seems like it's the more general 'Unresolved References' check, which can be very helpful. It's likely best to employ statement-level disabling of the feature, either by employing the menu as mentioned above, or by earmarked # noinspection PyUnresolvedReferences on the line preceding the statement.

You must first take a look at this. This interprets what occurs at the time you import a package. For convenience:

The import statement conduct the following convention: in case a package’s __init__.py code defines a list named __all__, it is taken to be the list of module names that must be imported when from package import * is encountered. It is up to the package author to keep this list up-to-date at the time a fresh version of the package is released. Package authors may also fix not to support it, in case they don’t see a use for importing * from their package.

Hence PyCharm respects this by displaying a warning message, so that the author can decide which of the modules get imported when * from the package is imported. Thus this appears to be helpful property of PyCharm (and in no way can it be named a bug, I suppose). You can simply remove this warning by including the names of the modules to be imported at the time your package is imported in the __all__ variable which is list, like this

__init__.py

from . import MyModule1, MyModule2, MyModule3
__all__ = [MyModule1, MyModule2, MyModule3]

Afterwards you include this, you can ctrl+click on these module names used in any other part of your project to directly jump to the declaration, which I often find very helpful.

10 6 4
31,120 points

Related questions

0 votes
1 answer 5 views
5 views
Problem: What is __init__.py for in a Python source directory?But just it contains an example, more information, and an explanation of namespace packages, the kind of packages without __init__.py.
asked Feb 21 Mashhoodch 9.6k points
0 votes
1 answer 11 views
11 views
Problem: the system cannot find the file specified in python
asked Feb 21 kaash_kashi 1.2k points
0 votes
1 answer 32 views
32 views
Problem: What is the purpose of __ init __? Is __ init __ necessary in Python? What does __ init __ return? Whenever object oriented programming is done in Python, we mostly come across __init__ method which we usually don’t fully understand. This article explains the main concept of __init__ but before understanding the __init__ some prerequisites are required.
asked Jan 6 Mashhoodch 9.6k points
0 votes
1 answer 13 views
13 views
373 I'm learning the Python programming language and I've came across something I don't fully understand. In a method like: def method(self, blah): def __init__(?): .... .... What does self do? What is it meant to be? Is it mandatory? What does the __init__ method do? Why is it necessary? (etc.) I think they might be OOP constructs, but I don't know very much.
asked Oct 25, 2020 psandprop 2.4k points
1 vote
1 answer 21 views
21 views
Problem: I have a program that is organized like: Sources |--__init__.py |--Additions |--__init__.py |--Add.py |--Collaboration |--__init__.py |--Colab.py |--Views |--__init__.py |--views.py |--Model |--__init__.py |--Models.py Can anybody explain me the “__init__.py” that is in every file?
asked May 4, 2020 samhaz 5k points
0 votes
1 answer 87 views
87 views
Please I would like to know how I can solve this error during programming : filenotfounderror: [winerror 2] the system cannot find the specified file
asked Oct 23, 2020 psandprop 2.4k points
1 vote
1 answer 222 views
222 views
Problem: I have recently started learning file handling with Python. I am currently having the folder which is full of pdf files. My task is to remove all the spaces from all the file names and then try to replace them with the underscores. Please find below the code ... my issue, but I have tried to look all over and still unable to find the solution for my above error related to file handling.
asked Jun 2, 2020 Martin K 6.6k points
0 votes
1 answer 1 view
1 view
Solution: How to fix this error: python __new__ vs __init__ HELP! I need help understanding this error: python __new__ vs __init__ Can someone please help fix this, I am new in python() : python __new__ vs __init__
asked 12 hours ago Mashhoodch 9.6k points
0 votes
1 answer 7 views
7 views
Problem: I'm trying to understand the use of super(). From the looks of it, both child classes can be created, just fine. I'm curious to know about the actual difference between the following 2 child classes. class Base(object): def __init__(self): print "Base ... ): def __init__(self): Base.__init__(self) class ChildB(Base): def __init__(self): super(ChildB, self).__init__() ChildA() ChildB()
asked Feb 18 Mashhoodch 9.6k points