Ошибка: неизвестный импорт "утилит", но код работает - PullRequest
0 голосов
/ 02 августа 2020

В моем коде я получаю эту ошибку, сообщающую мне, что он не распознает мой импорт:

enter image description here

This has kind of fixed the problem, in VSCode, instead of opening a large folder which has other sub folder, I opened only 1 of the folders:

enter image description here

I am not sure what is causing this problem as, the code which I have written uses data and functions in the files from utils folder. This means that my app is running flawlessly with no errors even though I am getting this unresolved import warning. Is there any way to fix this? Thanks a lot and I really appreciate your help!

My app crashes when I say .utils.constants as it says that there is no parent package / module.

Here is my complete file structure in VSCode:

enter image description here enter image description here The happened with PyCharm:

введите описание изображения здесь

Ответы [ 2 ]

1 голос
/ 02 августа 2020

Я полагаю, Pycharm не идентифицирует источник root проекта. Вы можете выбрать каталог Local Memory в качестве источника root.

Вы можете выполнить следующие шаги, чтобы выбрать Local Memory как источник root в Pycharm:

  • Щелкните правой кнопкой мыши на Local Memory на боковой панели Project.
  • Щелкните Mark Directory as> Sources root.

Вам не нужно добавлять . перед utils в операторе импорта .

Демонстрация:

Я удалил аналогичную unresolved import ошибку из Pycharm.

Перед тем, как выбрать каталог как Source root, я получал ошибка unresolved import в Pycharm, как показано ниже:

beofore source root

Then I marked the utils folder as source root and the error is fixed. After the source root mark, the folder icon is shown as a blue folder icon like below:

after source root mark

Reference:

0 голосов
/ 02 августа 2020

Проблема с Pycharm. Если вы хотите удалить ошибку, Pycharm должен сканировать файлы для индексации

После индексации он обновит интерпретатор python, тогда он должен работать! Сканирование файлов для индексации

Удачи

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...