cannot find reference in init py

Только начинаю изучать Python и решил написать игру. Выдает ошибку, что

C чем может быть связана данная проблема и как её решить?

Вот полное описание ошибки

    23 0
  • 7 янв 2017 2017-01-07 02:52:27
  • Михаил

gohlke/pythonlibs/#pygame скачал pygame‑1.9.3‑cp36‑cp36m‑win_amd64.whl. Далее распаковал его, как .zip и скинул в папку Python34 файлы, что куда кидал если честно не помню, делал по какому-то видео. Если не сложно не могли бы вы скинуть ссылку на ресурсы или рассказать, как это делать правильно ? — Михаил 7 янв 2017 2017-01-07 08:33:34.000000

I have a project in Pycharm organized as follows:

All of my __init__.py, except for the one right above Sources are blank files. I am receiving a lot of warnings of the kind:

Cannot find reference ‘xxx’ in __init__.py

For example, my FiltersController.py has this piece of code:

And I get this warning:

Cannot find reference ‘choice’ in __init__.py

I’m googling wondering what does this mean and what should I do to code properly in Python.

Thank you in advance.

6 Answers 6

This is a bug in pycharm. PyCharm seems to be expecting the referenced module to be included in an __all__ = [] statement.

For proper coding etiquette, should you include the __all__ statement from your modules? ..this is actually the question we hear young Spock answering while he was being tested, to which he responded: «It is morally praiseworthy but not morally obligatory.»

To get around it, you can simply disable that (extremely non-critical) (highly useful) inspection globally, or suppress it for the specific function or statement.

  • put the caret over the erroring text (‘choice’, from your example above)
  • Bring up the intention menu (alt-enter by default, mine is set to alt-backspace)
  • hit the right arrow to open the submenu, and select the relevant action

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.

I know this is quite a bit after you asked your question, but I hope this helps (you, or someone else).

Edited: Originally, I thought that this was specific to checking __all__ , but it looks like it’s the more general ‘Unresolved References’ check, which can be very useful. It’s probably best to use statement-level disabling of the feature, either by using the menu as mentioned above, or by specifying # noinspection PyUnresolvedReferences on the line preceding the statement.

Только начинаю изучать Python и решил написать игру. Выдает ошибку, что

C чем может быть связана данная проблема и как её решить?

Оцените статью