问题描述
我正在尝试使用 cx-freeze 中的 python 文件创建可执行文件,但是当我运行 setup.py 时,它会创建一些文件并产生一个长错误。 我的 setup.py:
import sys
from cx_Freeze import setup,Executable
additional_modules = []
build_exe_options = {"includes": additional_modules,"packages": ["sys","random"],"excludes": [],"include_files": []}
base = None
if sys.platform == "win32":
base = "win32gui"
setup(name="hangman",version="2.1",description="the Traditional hangman",options={"build_exe": build_exe_options},executables=[Executable(script="hangmandesktop.py",base=base)])
我的 hangmanm.py 脚本:
import tkinter as tk
word = ""
guessedLetters = ""
revealingWord = list("")
numberGuessedLetters = 0
numberWrongGuessedLetters = 0
def findOccurrences(s,ch):
return [i for i,letter in enumerate(s) if letter == ch]
def you_win():
print("You Win")
def word_submit_click(event):
global revealingWord
global word
if wordEntry.get() != "":
word = wordEntry.get()
wordEntry.delete(0,tk.END)
revealingWord.clear()
for i in range(len(word)):
revealingWord.append("_")
revealingWord.append(" ")
revealingWordTemp = revealingWord
guessingWordLabel.config(text = "".join(revealingWordTemp))
else:
print("THAT ISN'T A WORD")
def letter_submit_click(event):
global revealingWord
global guessedLetters
global numberGuessedLetters
global word
if letterEntry.get() != "" and word != "":
if letterEntry.get()[0] in guessedLetters:
print("You already guessed that letter!")
else:
guessedLetters += (letterEntry.get()[0] + " ")
if letterEntry.get()[0] in word:
for i in findOccurrences(word,letterEntry.get()[0]):
revealingWord[2 * i] = letterEntry.get()[0]
numberGuessedLetters += 1
print (numberGuessedLetters)
revealingWordTemp = revealingWord
guessingWordLabel.config(text = "".join(revealingWordTemp))
print("You guessed: " + letterEntry.get()[0])
if numberGuessedLetters >= len(word):
you_win()
else:
print("incorrect guess")
guessedLettersLabel.config(text = guessedLetters)
letterEntry.delete(0,tk.END)
window = tk.Tk()
window.title("Hangman")
winLabel = tk.Label(text = "",width = 100,height = 2,font = 200)
winLabel.pack()
tk.Label(text = "Input the word here:",font = 200).pack()
wordFrame = tk.Frame()
wordFrame.pack()
wordEntry = tk.Entry(width = 80,font = 50,master = wordFrame)
wordEntry.pack(side = tk.LEFT)
wordSubmit = tk.Button(text = "Submit",master = wordFrame)
wordSubmit.pack(side = tk.RIGHT)
guessingWordLabel = tk.Label(text = "",height = 5,font = 200)
guessingWordLabel.pack()
tk.Label(text = "Input your letter guess here:",font = 200).pack()
letterFrame = tk.Frame()
letterFrame.pack()
letterEntry = tk.Entry(width = 40,master = letterFrame)
letterEntry.pack(side = tk.LEFT)
letterSubmit = tk.Button(text = "Submit",master = letterFrame)
letterSubmit.pack(side = tk.LEFT)
guessedLettersLabel = tk.Label(text = "Guessed Letters go here",font = 200)
guessedLettersLabel.pack()
wordSubmit.bind("<Button-1>",word_submit_click)
letterSubmit.bind("<Button-1>",letter_submit_click)
window.mainloop()
running build
running build_exe
error during GetDependentFiles() of 'c:\\users\\####\\#####\\#####\\microsoft\\windowsapps\\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\\python.exe': (0,'The file cannot be accessed by the system','c:\\users\\#####\\####\\####\\microsoft\\windowsapps\\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\\python.exe',1920,None)
creating directory build\exe.win-amd64-3.8
copying c:\program files\windowsapps\pythonsoftwarefoundation.python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\python38.dll -> build\exe.win-amd64-3.8\python38.dll
copying c:\program files\windowsapps\pythonsoftwarefoundation.python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\python3.dll -> build\exe.win-amd64-3.8\python3.dll
copying c:\program files\adoptopenjdk\jdk-14.0.#.12-hotspot\bin\api-ms-win-crt-stdio-l1-1-0.dll -> build\exe.win-amd64-3.8\api-ms-win-crt-stdio-l1-1-0.dll
copying c:\program files\adoptopenjdk\jdk-14.0.#.12-hotspot\bin\api-ms-win-crt-locale-l1-1-0.dll -> build\exe.win-amd64-3.8\api-ms-win-crt-locale-l1-1-0.dll
copying c:\program files\adoptopenjdk\jdk-14.0.#.12-hotspot\bin\api-ms-win-crt-heap-l1-1-0.dll -> build\exe.win-amd64-3.8\api-ms-win-crt-heap-l1-1-0.dll
copying c:\program files\windowsapps\pythonsoftwarefoundation.python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\vcruntime140.dll -> build\exe.win-amd64-3.8\vcruntime140.dll
copying c:\program files\adoptopenjdk\jdk-14.0.#.12-hotspot\bin\api-ms-win-crt-math-l1-1-0.dll -> build\exe.win-amd64-3.8\api-ms-win-crt-math-l1-1-0.dll
copying c:\program files\adoptopenjdk\jdk-14.0.#.12-hotspot\bin\api-ms-win-crt-runtime-l1-1-0.dll -> build\exe.win-amd64-3.8\api-ms-win-crt-runtime-l1-1-0.dll
copying C:\Users\####\####\####\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\python38\site-packages\cx_Freeze\bases\win32gui.exe -> build\exe.win-amd64-3.8\hangmandesktop.exe
Traceback (most recent call last):
File "setup.py",line 16,in <module>
setup(name="hangman",File "C:\Users\####\####\####\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\python38\site-packages\cx_Freeze\dist.py",line 392,in setup
distutils.core.setup(**attrs)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\distutils\core.py",line 148,in setup
dist.run_commands()
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\distutils\dist.py",line 966,in run_commands
self.run_command(cmd)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\distutils\dist.py",line 985,in run_command
cmd_obj.run()
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\distutils\command\build.py",line 135,in run
self.run_command(cmd_name)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\distutils\cmd.py",line 313,in run_command
self.distribution.run_command(command)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\distutils\dist.py",in run_command
cmd_obj.run()
File "C:\Users\######\#####\#####\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\python38\site-packages\cx_Freeze\dist.py",line 260,in run
freezer.Freeze()
File "C:\Users\#####\#####\#####\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\python38\site-packages\cx_Freeze\freezer.py",line 754,in Freeze
self._FreezeExecutable(executable)
File "C:\Users\####\####\####\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\python38\site-packages\cx_Freeze\freezer.py",line 316,in _FreezeExecutable
self._AddVersionResource(exe)
File "C:\Users\#####\#####\#####\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\python38\site-packages\cx_Freeze\freezer.py",line 115,in _AddVersionResource
stamp(fileName,versionInfo)
File "C:\Users\####\####\####\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\python38\site-packages\win32\lib\win32verstamp.py",line 163,in stamp
h = BeginUpdateResource(pathname,0)
pywintypes.error: (2,'BeginUpdateResource','The system cannot find the file specified.')
请帮助没有其他转换器,例如 pyinstaller 工作,他们没有得到那么远,我得到了一个由此产生的 exe,但是当打开命令提示符时,以非常快的速度打开和关闭,但没有任何反应。 提前致谢
编辑:重新安装 python 然后使用对我有用的虚拟环境。我认为问题在于包装轮冲突。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)