将数据捆绑在一个文件中

时间:2018-09-24 12:55:34

标签: python python-3.x pyinstaller

所以我正在努力将数据文件捆绑成(一个文件)。我读了堆栈溢出,但似乎不起作用。 这是我在代码中输入的内容:

def resource_path(relative_path):

    try:

        base_path = sys._MEIPASS

    except Exception:
        base_path = os.path.abspath(".")

    return os.path.join(base_path, relative_path)

resource_path("highscore.txt")

添加其他文件时,我花了一些时间。我从代码中得到的错误是:(我使用PyTutorials创建的自动转换器)在这里:https://www.youtube.com/watch?v=OZSZHmWSOeM&lc=z22hjly4ko3bitzudacdp4321m5xbgmhbvuf5rv2hrpw03c010c.1537706801502204

回溯(最近通话最近一次):

File "Game2.1.py", line 78, in <module>
File "Game2.1.py", line 20, in file_to_list
FileNotFoundError: [Errno 2] No such file or directory: 'highscore.txt'
[7004] Failed to execute script Game2.1

使用目录可以完美工作,转换器本身也没有问题 我做错什么了?

0 个答案:

没有答案