Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在_uinit__u;.py中断pyinstaller时正确导入文件_Python_Python 3.x_Python Import_Pyinstaller - Fatal编程技术网

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