【发布时间】:2022-02-22 02:31:15
【问题描述】:
我做不到。
我的结构是:
program_name/
__init__.py
setup.py
src/
__init__.py
Process/
__init__.py
thefile.py
tests/
__init__.py
thetest.py
thetest.py:
from ..src.Process.thefile.py import sth
运行:pytest ./tests/thetest.py from program_name 给出:
ValueError: attempted relative import beyond top-level package
我也尝试了其他方法,但收到各种错误。
但我希望上述方法能够奏效。
【问题讨论】:
-
你试过
import Process.thefile吗?我假设您正在尝试从顶级文件夹运行程序 -
@ssm: 它给出了'No module named..'
-
试试
from Process import thefile -
@ssm: 它仍然没有给出任何命名的模块。
-
哈哈,对不起,我的错。
from src.Process import thefile这个应该可以工作...