0

I'm new with python and I'm trying to import one module for using some functions but I'm having issues with it. This is my directory:

enter image description here

This is my source path:

/home/adrian/eclipse-workspace/Desarrollos/desarollos_backend_HLC_filters/website_base_filter_2/controllers/generic_functions.py

This is my class inside the file.

class CustomerPortalFilters(CustomerPortal):
 def hola(self):
 print('que pasa')

From the module website_invoice_filter_2 I need to import the file generic_functions.py from website_base_filter_2.

This is my try, but Eclipse IDE cannot resolve it.

from Desarrollos.desarollos_backend_HLC_filters.website_base_filter_2.controllers.generic_functions import CustomerPortalFilters

enter image description here

Thanks for reading.

asked Jun 2, 2020 at 8:59
2
  • 1
    There need to be an __init__.py in all directories all the way down to the file you want to import. Could you try to add one in each directory and try again? Commented Jun 2, 2020 at 9:02
  • Created the file but I'm not able to make the impòrt structure correctly. @HampusLarsson Commented Jun 2, 2020 at 9:08

1 Answer 1

1

You need to add __init__.py at the root level in order to use it in the import.

Just create a new empty file named __init__.py and try again. Basically it will tell the interpreter that it is a python directory so that you can use it in other python files.

answered Jun 2, 2020 at 9:06
Sign up to request clarification or add additional context in comments.

5 Comments

Created the file but I'm not able to make the import structure navigating into folders. @Jay Patel
Can you try by giving relative path, like ../website_base_filter_2.controllers.generic_functions
In the init.py file or in the website_base_filter file? @Jay Patel
In the file where you're trying to import that module
In the file website_invoice_filters_2/controllers/invoices.py. In the directory structure is in the same level as website_base_filter_2 @Jay Patel

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.