I am trying to create an executable with a python file in cx-freeze, however when I run the setup.py it creates some of the files and the produces a long error. my 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)])
my hangmanm.py script:
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:", width = 100, height = 2, 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:", width = 100, height = 5, font = 200).pack()
letterFrame = tk.Frame()
letterFrame.pack()
letterEntry = tk.Entry(width = 40, font = 50, 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", width = 100, height = 5, font = 200)
guessedLettersLabel.pack()
wordSubmit.bind("<Button-1>", word_submit_click)
letterSubmit.bind("<Button-1>", letter_submit_click)
window.mainloop()
and the error I get from the command prompt is:
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", line 985, 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.')
please help no other converters such as pyinstaller work, they don't get as far, i get an exe produced from this but when opens the command prompt opens and closes at a very fast speed and nothing happens. thanks in advance
EDIT: re-installing python then using a virtual environment worked for me. I believe the issue was conflicting package wheels.