python - 在 Pyinstaller App 的子目录中包含并启动 py 文件
问题描述
(Mac,python 3.9,pyinstaller)为了组织,我将一些 .py 文件放在我的主要 python 代码的子目录中。这些 .py 文件是从上层目录中的另一个脚本调用的,它们会在子目录中创建一些 csv 文件。
/Main/GUI.py <--调用 /Sub/CreateCSV.py /Main/Sub/CreateCSV.py
我试图使用 pyinstaller 创建一个可以让同事运行的应用程序。我在链接子目录中的 .py 文件时遇到问题。
我在 Analysis 结构的 .spec 文件中添加了一个数据调用:
datas=[ ('Sub/*', 'Sub')],
pyinstaller 将毫无错误地运行,我在 Main/dist/main/ 文件夹中看到 /sub 文件。我已经打印了脚本的运行目录,它不是从 Main/dist 运行的,它的运行位置是:/var/folders/sk/55lnhvws0qz5rsddrtjln8lw0000gn/T/_MEIeOEezI
这就是我在子目录中调用 .py 文件的方式:
def execfile(filepath, globals=None, locals=None):
Function for executing another python file
if globals is None:
globals = {}
globals.update({
"__file__": filepath,
"__name__": "__main__",
})
with open(filepath, 'rb') as file:
exec(compile(file.read(), filepath, 'exec'), globals, locals)
if not os.path.exists('./Sub/random.csv'):
execfile("/Sub/CreateCSV.py)
终端输出给了我错误代码: FileNotFoundError: [Errno 2] No such file or directory: '/Sub/CreateCSV.py'
有什么建议么?
解决方案
推荐阅读
- python - dateutil 解析器无法解析 dd mm yyyy
- pandas - 从熊猫数据框中的字符串日期获取一年中的哪一天
- multithreading - 运行空间线程中的 $MyInvocation
- xml - 使用 perl 扫描/读取内部 Excel xml 文件 app.xml
- redis - 需要了解redis的基础知识
- c# - C# 无法将 List 转换为 DataTable
- angular - 循环内多次调用
- swift3 - 如何在 Swift 3 上从 JSON 获取每个数据?
- excel - 如何计算具有特定月份和颜色的单元格数量
- python - Python:如何合并 Python 类?