简体   繁体   English

cx_freeze attributeerror: 'windowspath' object 没有属性 'write' 错误

[英]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.

相关问题 windows cx_freeze 上的“AttributeError: 'NoneType' object 没有属性写入” - “AttributeError: ‘NoneType’ object has no attribute write” on windows cx_freeze cx_Freeze属性错误:“列表”对象没有属性“项目” - cx_Freeze Attribute error: 'list' object has no attribute 'items' 使用 cx_Freeze 将 python 文件转换为可执行文件,然后得到错误 AttributeError: &#39;list&#39; object has no attribute &#39;main_script&#39; - Convert a python file into an executable with cx_Freeze then get error AttributeError: 'list' object has no attribute 'main_script' cx_Freeze + curses:“ NoneType”对象没有属性“ fileno” - cx_Freeze + curses: 'NoneType' object has no attribute 'fileno' cx_Freeze“列表”对象没有属性“项目” - cx_Freeze 'list' object has no attribute 'items' 使自动更新zip cx_freeze和esky&#39;Freezer&#39;对象没有属性&#39;createLibraryZip&#39;时出错 - Error making auto-update zip cx_freeze and esky 'Freezer' object has no attribute 'createLibraryZip' Python 3.3 cx_freeze奇怪的错误:“ NoneType”对象没有属性“ path” - Python 3.3 cx_freeze weird error: 'NoneType' object has no attribute 'path' AttributeError: &#39;WindowsPath&#39; 对象没有属性 &#39;endswith&#39; - AttributeError: 'WindowsPath' object has no attribute 'endswith' cx_freeze AttributeError:模块&#39;dis&#39;没有属性&#39;_unpack_opargs&#39; - cx_freeze AttributeError: module 'dis' has no attribute '_unpack_opargs' Python,AttributeError:cx_Freeze 构建后,模块“google.cloud.bigquery”没有属性“Client” - Python, AttributeError: module 'google.cloud.bigquery' has no attribute 'Client' after cx_Freeze build
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM