Today I have a problem with module in Python. My file structure:
- library
--- Storage.py
- scripts
--- run.py
and run.py code:
import library.Storage as Storage
but I run this in PyCharm it work fine but if I run in terminal
python3 scripts/run.py
it return
import library.Storage as Storage
ModuleNotFoundError: No module named 'library'
I had tried this
fpath = os.path.dirname(__file__)
sys.path.append(fpath)
print(sys.path)
['/opt/homebrew/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python39.zip', '/opt/homebrew/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9', '/opt/homebrew/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload', '/opt/homebrew/lib/python3.9/site-packages', '/Users/binhot/PycharmProjects/MyProject/']
but the problems still happen