Skip to content

Instantly share code, notes, and snippets.

@teshanshanuka
Created October 20, 2020 09:30
Show Gist options
  • Save teshanshanuka/2d5775d163c9bce784abc9b88cedf7b0 to your computer and use it in GitHub Desktop.
Save teshanshanuka/2d5775d163c9bce784abc9b88cedf7b0 to your computer and use it in GitHub Desktop.
Python3 import problem - folder structure
#!/bin/bash -e
# Question: https://stackoverflow.com/questions/64427513/python3-package-file-cannot-import-from-same-directory-when-used-in-a-different?noredirect=1#comment113946981_64427513
mkdir -p pyprob/mypkg
cd pyprob/mypkg
touch __init__.py
cat > foolib.py << EOF
def foo():
pass
EOF
cat > barlib.py << EOF
from foolib import foo
def bar():
foo()
EOF
cat > pmain.py << EOF
from barlib import bar
bar()
EOF
cd ..
cat > main.py << EOF
from mypkg.barlib import bar
bar()
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment