Nameko框架写的微服务启动时出现问题。通过命令启动微服务时
nameko run name_file_with_class_microservice
抛出以下异常:
Traceback (most recent call last):
File "/home/user/.pyenv/versions/project/bin/nameko", line 33, in <module>
sys.exit(load_entry_point('nameko==2.12.0', 'console_scripts', 'nameko')())
File "/home/user/.pyenv/versions/project/lib/python3.9/site-packages/nameko/cli/main.py", line 112, in main
args.main(args)
File "/home/user/.pyenv/versions/project/lib/python3.9/site-packages/nameko/cli/commands.py", line 110, in main
main(args)
File "/home/user/.pyenv/versions/project/lib/python3.9/site-packages/nameko/cli/run.py", line 181, in main
import_service(path)
File "/home/user/.pyenv/versions/project/lib/python3.9/site-packages/nameko/cli/run.py", line 46, in import_service
__import__(module_name)
File "./main.py", line 18, in <module>
from commands.object import ObjectUpdateCommand, ObjectExportCommand
File "./commands/object/__init__.py", line 1, in <module>
from .object_export import ObjectExportCommand
File "./commands/object/object_export.py", line 6, in <module>
from ...exception import ProxyException
ImportError: attempted relative import beyond top-level package
我知道这与“sys.path”变量以及启动的来源有关。但是,我不明白如何使导入对整个项目以及其中的单独微服务都可行(是的,微服务被合并到一个存储库中,每个存储库都编写了自己的 docker-file)
如果您指定相对于微服务起点的绝对路径,一切正常。但是这并不适合整个项目,PyCharm 表示导入曲线,自动补全不起作用等等。