Reputation: 183
I have been trying to import files into my main.py file by using imports from the sources root. Here is a pic of my file structure...
I am simply using source root imports to try and import seed.py into my main.py file. but keep getting this error message.
**ModuleNotFoundError: No module named 'app'**
This makes no sense to me as my app is a module and has its own init file. Im not too sure If i have something incorrect in my file structure or if it is just pycharm being buggy. But i dont see a reason why this import shouldnt work.
here is a code snippet of the import statement I am using
from app.bitcoinBackend.seed import *
any ideas??
Upvotes: 1
Views: 2175
Reputation: 183
Okays so the solution i found involved moving main.py out of the frontend module back into the app directory. Here is an image of the full restructure.
next you had to select a directory as sources root I haven't looked into it too much, but when I correctly selected the sources root, all sub dirs changed into having the appropriate module symbol. (you can see this is app and bitcoinBackend)
I selected the teamSoftwareProject as the sources root. There are two ways of doing this one way involves
Here is an image
The other method is
Here is an image of this method.
Finally I added init.py files to all other sub dirs
Then importing from the project root worked.
from app.bitcoinBackend.seed import *
Upvotes: 0
Reputation: 126
Maybe you should try move your main.py to the root folder of app and just call bitcoinBackend.seed import *. Because your main is in a subfolder of app.
Upvotes: 1