Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pycharm is showing error in module import resolution even if program is working fine

Tags:

python

pycharm

I am new in Python and pycharm ide. I have created one of my own module and importing it in another python file. Both of my python files are in same direcotary and parent directory has been made Sources Root directory.

Now my program is working fine but pycharm ide is showing error in import statement and on hover prompting no such module.

I am not sure if i am doing something wrong please let me know what is the proper way to import a module.

here is my project structure - Main.py is importing Greeting.py and getting error.test is a root directory. Main.py

Greeting.py

like image 728
prashant sindhu Avatar asked Mar 07 '23 19:03

prashant sindhu


2 Answers

For my case, I had my problem was not resolved by invalidating the cache, My problem was with the directories (packages) and the root directory. Here was my structure.

MyApp:
|
|----my_first_app
|--------my_first_app_files
|--------my_first_app_directories
|----my_second_app
|--------my_second_app_files
|--------my_second_app_directories

So what I did on my editor was I right clicked app:>mark directory as:>sources root

Referrence

Link

like image 156
Fahd Jamy Avatar answered Mar 26 '23 10:03

Fahd Jamy


invalidate cache and restart resolved the problem.

jetbrains.com/help/pycharm/cleaning-system-cache.html

like image 34
prashant sindhu Avatar answered Mar 26 '23 10:03

prashant sindhu