[Tutor] sibling import

Alan Gauld alan.gauld at yahoo.co.uk
Thu Oct 12 17:00:53 EDT 2017

On 12/10/17 12:15, Atar new wrote:

> Here is my problem. I want to use sibling import but it is not working . I
> know taht if we add the directory in sys.path ,it will work.

Why not put the package in the same folder as your
top level script? I think that should work.

> But I have to package the whole application and will create a setup.py file
> out of it .

In that case either install the packages in the standard
package area for your system so that they will be within
sys.path or, as above, put everything under a single root

> What is the standard way to do it?

mkdir PROJ

>    1. mkdir A
>    3.
>    4. touch A/__init__.py
>    6.
>    7. touch A/foo.py
>    8. touch bar.py
>    9.
>    10. cat bar.py
>    11. from A import foo
>    12.
>    13.
>    14. python bar.py

Should work I think.

Alan G
Author of the Learn to Program web site
Follow my photo-blog on Flickr at:

More information about the Tutor mailing list