Скрипт cx_Freeze сообщает, что в моей программе есть ошибки, когда в исходном файле нет ошибок - PullRequest
0 голосов
/ 14 марта 2020

Я пытаюсь преобразовать проект tkinter в .exe, но я сталкиваюсь с этой проблемой, когда запускаю свой скрипт cx_Freeze.

C:\Users\Nathan>py "C:\Users\Nathan\Desktop\Coding\Langs\Python\Projects\Media Player" cxf.py build
Traceback (most recent call last):
  File "D:\Pytenlel\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "D:\Pytenlel\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\Nathan\Desktop\Coding\Langs\Python\Projects\Media Player\__main__.py", line 227, in <module>
    Ppause = PhotoImage(file = r"Assets\Pause.png") # Program Images
  File "D:\Pytenlel\lib\tkinter\__init__.py", line 3539, in __init__
    Image.__init__(self, 'photo', name, cnf, master, **kw)
  File "D:\Pytenlel\lib\tkinter\__init__.py", line 3495, in __init__
    self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't open "Assets\Pause.png": no such file or directory

В моей программе tkinter у меня есть список переменных, которые все PhotoImages

Ppause = PhotoImage(file = r"Assets\Pause.png") # Program Images
Pplay = PhotoImage(file = r"Assets\Play.png")
Pnext = PhotoImage(file = r"Assets\NextSong.png")
Plast = PhotoImage(file = r"Assets\PrevSong.png")
Padd = PhotoImage(file = r"Assets\Add.png")
Premove = PhotoImage(file = r"Assets\Remove.png")
Pup = PhotoImage(file = r"Assets\Up.png")
Pdown = PhotoImage(file = r"Assets\Down.png")
Pstop = PhotoImage(file = r"Assets\Stop.png")

И эта проблема возникает в каждой строке этого списка переменных. Когда я запускаю свой обычный (__main__.py) скрипт, он работает нормально и ошибок нет (также мои __main__.py и файл cx_Freeze находятся в одной папке).

Вот код, который я использую чтобы преобразовать мой .py в .exe

import cx_Freeze

import sys
from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os", "tkinter", "vlc", "winsound"], "excludes": []}

# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == "win32":
    base = "Win32GUI"

setup(  name = "Earworm",
        version = "0.2",
        description = "Earworm Media/Song player",
        options = {"build_exe": build_exe_options},
        executables = [Executable("__main__.py", base=base)])

Я скопировал это из их документации, так как я начинающий в cx_Freeze.

...