Code: Select all
.
└── src
├── __init__.py
├── lib
│ ├── hello.py
│ └── __init__.py
├── libtwo
│ ├── __init__.py
│ └── world.py
└── main.py
< /code>
world.py
def helloworld():
print("Hello World!")
< /code>
hello.py
from libtwo.world import helloworld
helloworld()
< /code>
Main.py
from libtwo.world import helloworld
helloworld()
< /code>
(es läuft gut von main.py) < /p>
File "src/lib/hello.py", line 1, in
from libtwo.world import helloworld
ModuleNotFoundError: No module named 'libtwo'
< /code>
Folgende gibt < /p>
File "lib/hello.py", line 1, in
from ..libtwo.world import helloworld
ImportError: attempted relative import with no known parent package
< /code>
from ..libtwo.world import helloworld
helloworld()
< /code>
Verwenden von VSCODE
Ich habe versucht, Arbeitsbereiche und Konfigurationen einzurichten.
"python.terminal.executeInFileDir": true
virtuelle SYS -Pfadeinträge.
Laut einigen Quellen, wenn ich mein Verzeichnis im Virtualenv nicht sehe, bedeutet dies, dass etwas nicht stimmt < /p>
Code: Select all
(my_venv) ➜ src python main.py
>>> import sys
>>> sys.path
['', '/usr/lib/python38.zip', '/usr/lib/python3.8', '/usr/lib/python3.8/lib-dynload', '/home/user/Documents/py/myui/subject_a/my_venv/lib/python3.8/site-packages']
>>>
< /code>
Sys.Path von main.py < /p>
Ausführen(my_venv) ➜ src python main.py
['/home/user/Documents/py/myui/subject_a/src', '/usr/lib/python38.zip', '/usr/lib/python3.8', '/usr/lib/python3.8/lib-dynload', '/home/user/Documents/py/myui/subject_a/my_venv/lib/python3.8/site-packages']