I am facing a problem in importing modules in python. I looked for a solution and found this. but this did not worked either.
My Directory is as follows
->MyScrapper
--->MyScrapper
----->db_connection.py
--->Video_Scrapper
-----> video_scrapper.py
--->Blogs_Scrapper
-----> blogs_scrapper.py
I want to import db_connection.py in video_scrapper.py as well as blogs_scrapper.py. I have tried to import it as from MyScrapper.db_connection import DBConnection. It throws a ModuleNotFoundError: No Module named 'MyScrapper'. I have also tried using from db_connection import DBConnection and import DBConnection but none of them worked.
Please Help!!
When importing a module in python, it will search the module in this order:
So, you need to add the MyScrapper module to the search path. If you use a virtual environment, you can add your project root directory into the PYTHONPATH, by modify the PYTHONPATH in the Scripts\activate.bat file, like this:
I use the virtual environment, and my project struct is:
|--Include
|--Lib
|--Scripts
|--src
My source files are in the src directory.