[英]cx_freeze attributeerror: 'windowspath' object has no attribute 'write' error
I got this error while trying to convert my.py file to.exe file with Cx_Freeze:尝试使用 Cx_Freeze 将 my.py 文件转换为 .exe 文件时出现此错误:
cx_freeze attributeerror: 'windowspath' object has no attribute 'write' error
The file I'm trying to convert:我要转换的文件:
print("Hello!")
while True:
pass
Setup.py file:安装.py文件:
from cx_Freeze import setup, Executable
setup( name = "HW" ,
version = "0.1" ,
description = "Hello World App" ,
executables = [Executable("file.py")] ,
)
The full console output(only errors):完整的控制台输出(只有错误):
Traceback (most recent call last):
File "C:\Users\Muhammed\Desktop\a.py", line 6, in <module>
executables = [Executable("b.py")] ,
File "C:\Users\Muhammed\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\dist.py", line 447, in setup
setuptools.setup(**attrs)
File "C:\Users\Muhammed\AppData\Local\Programs\Python\Python36\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "C:\Users\Muhammed\AppData\Local\Programs\Python\Python36\lib\distutils\dist.py", line 955, in run_commands
self.run_command(cmd)
File "C:\Users\Muhammed\AppData\Local\Programs\Python\Python36\lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "C:\Users\Muhammed\AppData\Local\Programs\Python\Python36\lib\distutils\command\build.py", line 135, in run
self.run_command(cmd_name)
File "C:\Users\Muhammed\AppData\Local\Programs\Python\Python36\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "C:\Users\Muhammed\AppData\Local\Programs\Python\Python36\lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "C:\Users\Muhammed\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\dist.py", line 317, in run
freezer.Freeze()
File "C:\Users\Muhammed\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\freezer.py", line 623, in Freeze
self._write_modules(library_zip, finder)
File "C:\Users\Muhammed\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\freezer.py", line 568, in _write_modules
outFile.writestr(zinfo, data)
File "C:\Users\Muhammed\AppData\Local\Programs\Python\Python36\lib\zipfile.py", line 1644, in writestr
with self.open(zinfo, mode='w') as dest:
File "C:\Users\Muhammed\AppData\Local\Programs\Python\Python36\lib\zipfile.py", line 1348, in open
return self._open_to_write(zinfo, force_zip64=force_zip64)
File "C:\Users\Muhammed\AppData\Local\Programs\Python\Python36\lib\zipfile.py", line 1461, in _open_to_write
self.fp.write(zinfo.FileHeader(zip64))
File "C:\Users\Muhammed\AppData\Local\Programs\Python\Python36\lib\zipfile.py", line 721, in write
n = self.fp.write(data)
AttributeError: 'WindowsPath' object has no attribute 'write'
Exception ignored in: <bound method ZipFile.__del__ of <zipfile.PyZipFile [closed]>>
Traceback (most recent call last):
File "C:\Users\Muhammed\AppData\Local\Programs\Python\Python36\lib\zipfile.py", line 1649, in __del__
self.close()
File "C:\Users\Muhammed\AppData\Local\Programs\Python\Python36\lib\zipfile.py", line 1667, in close
self._write_end_record()
File "C:\Users\Muhammed\AppData\Local\Programs\Python\Python36\lib\zipfile.py", line 1769, in _write_end_record
self.fp.write(endrec)
File "C:\Users\Muhammed\AppData\Local\Programs\Python\Python36\lib\zipfile.py", line 721, in write
n = self.fp.write(data)
AttributeError: 'WindowsPath' object has no attribute 'write'
I was not getting this error when using Windows 10, but I started getting this error when I upgraded my system to Windows 11.我在使用 Windows 10 时没有收到此错误,但当我将系统升级到 Windows 11 时开始收到此错误。
(I used Google Translate) (我用谷歌翻译)
I solved my problem like this: My Python version was 3.6.我这样解决了我的问题:我的 Python 版本是 3.6。 I got errors in many modules because of the python version.由于 python 版本,我在许多模块中都遇到了错误。 Thinking maybe that's why, I installed 3.8 and tried again.想也许这就是为什么,我安装了 3.8 并再次尝试。 This way my problem was solved.这样我的问题就解决了。
I also tried it on Windows 7 with the help of Virtual Box, I thought the problem was caused by Windows 11. I got the same error, upgraded to 3.8 and the problem was solved again.我也借助Virtual Box在Windows 7上试了一下,我以为问题出在Windows 11上。同样的错误,升级到3.8,问题又解决了。
(I used Google Translate) (我用谷歌翻译)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.