Created
October 20, 2020 09:30
-
-
Save teshanshanuka/2d5775d163c9bce784abc9b88cedf7b0 to your computer and use it in GitHub Desktop.
Python3 import problem - folder structure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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