I'm trying to build a simple project in Python,however I can't seem to wrap my head around how it's done despite reading the documentations over and over and reading example code.
I'm semi-new to Python, having a background of only single-file scripting. However I made numerous Node.js and Java projects with multiple folders and packages. In Python However I can't seem to grasp the project structure and workflow mechanisms- init.py, virtualenvs, setuptools etc. it all seems very alien and unintuitive to me, hurting my overall productivity(ironically Python is supposed to be a language aimed at productivity, right?)
My project has this example structure:
package_test (package)
|
|------- __init__.py
|------- main.py (entry point)
|
|------- /lib (modules)
| |
| |----- __init__.py
| |----- lib.py
|
|------- /Tests
| |
| |----- __init__.py
| |----- test.py
in main.py:
from lib import lib
lib.libtest()
in lib.py:
def libtest():
print("libtest")
in test.py:
from lib import lib
lib.libtest()
Running main.py works, However when running test.py it cannot find the module. I have tried solutions such as appending to sys.path, putting '..' before lib, and more- none have worked.
This is just an example, but I wish to develop more complex projects in Python with multiple subfolders in the future(I think Python has some cool features and nice libraries), yet this problem keeps bothering me. I never had to think about these issues when developing in Java or in Node, not to mention stuff such as virtualenv etc.
Thank you in Advance