Python 如何在_uinit__u;.py中断pyinstaller时正确导入文件
我解决了Python 如何在_uinit__u;.py中断pyinstaller时正确导入文件,python,python-3.x,python-import,pyinstaller,Python,Python 3.x,Python Import,Pyinstaller,我解决了pyinstaller的一个问题,解决问题的方法是从我的树中删除空的\uuuu init\uuuuuuy.py文件,因此我不再拥有该文件,一切正常。但是,现在我添加了更多文件,并且具有不同的文件夹结构: dist | +--- rating_service.exe # created by pyinstaller service | +--- rating_service.py shared | +--- resource_globals.py 在rating_service.py内
pyinstaller
的一个问题,解决问题的方法是从我的树中删除空的\uuuu init\uuuuuuy.py
文件,因此我不再拥有该文件,一切正常。但是,现在我添加了更多文件,并且具有不同的文件夹结构:
dist
|
+--- rating_service.exe # created by pyinstaller
service
|
+--- rating_service.py
shared
|
+--- resource_globals.py
在rating_service.py内部,我尝试了这些导入,但出现了以下错误:
from . import shared
ImportError:无法导入名称“共享”
ValueError:尝试在顶级包之外进行相对导入
ModuleNotFoundError:没有名为“共享”的模块
如何访问我的
分级服务中的资源\u全局内容
?如果无法添加任何\uuuu init\uuuuuuupy
文件,那么作为一项工作,您可以在分级服务.py中执行:
# -----------------
# rating_service.py
# -----------------
import os
import sys
# Manually add the 'shared' directory to the python search paths
file_dir = os.path.dirname(os.path.realpath(__file__))
shared_dir = os.path.join(file_dir, '../shared')
sys.path.insert(0, shared_dir)
import resource_globals
import shared
# -----------------
# rating_service.py
# -----------------
import os
import sys
# Manually add the 'shared' directory to the python search paths
file_dir = os.path.dirname(os.path.realpath(__file__))
shared_dir = os.path.join(file_dir, '../shared')
sys.path.insert(0, shared_dir)
import resource_globals