简体   繁体   中英

Python intra-package imports don't work at all

My directory structure is like the following:

toplevel/
    subdir/
        __init__.py
        foo/
          __init__.py
          foo.py
        bar/
          __init__.pt
          bar.py

if i try to from foo import foo in bar.py, and execute bar.py from subdir with python3 bar/bar.py it says foo was not found. I used os.getcwd() and it is toplevel/subdir , so it should work. I've tried relative imports, but none work.

If you must do this, you can use sys.path to see what paths interpreter can load module from.

and then via sys.append('path you want add') to add path

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM