miurahr / py7zr

7zip in python3 with ZStandard, PPMd, LZMA2, LZMA1, Delta, BCJ, BZip2, and Deflate compressions, and AES encryption.

Home Page:https://pypi.org/project/py7zr/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to create 7z/zip archive.

izhgtumekhanik opened this issue · comments

Describe the bug

AttributeError: 'SevenZipFile' object has no attribute 'header'

Related issue

To Reproduce

Steps to reproduce the behavior:
(example)

  1. install pip install py7zr (0.19.2 - 0.20.7)
  2. Run following code with python3.
import py7zr
with py7zr.SevenZipFile(r'C:\temp\test.7z', 'w') as archive:  #and zip
    archive.write(r'C:\temp\asd.txt')
    #archive.close()

Environment (please complete the following information):

  • OS: Windows 8.1x64
  • Python 3.8.10 (tags/v3.8.10:3d8993a, May 3 2021, 11:48:03) [MSC v.1928 64 bit (AMD64)]
  • py7zr version: (0.20.7, 0.20.6, 0.20.5, 0.20.4, 0.20.2, 0.20.0, 0.19.2)

Test data(please attach in the report):

Traceback (most recent call last):
  File "C:\Users\%UserProfile%\Desktop\111.py", line 15, in <module>
    archive.close()
  File "C:\Python38\Lib\site-packages\py7zr\py7zr.py", line 410, in __exit__
    self.close()
  File "C:\Python38\Lib\site-packages\py7zr\py7zr.py", line 1077, in close
    self._write_flush()
  File "C:\Python38\Lib\site-packages\py7zr\py7zr.py", line 686, in _write_flush
    if self.header._initialized:
AttributeError: 'SevenZipFile' object has no attribute 'header'

Additional context

For Windows 10x64 Pro 22H2

Describe the bug
ModuleNotFoundError: No module named 'bcj._bcj'
I installed: pip install bcj-cffi ==> error: ModuleNotFoundError: No module named 'inflate64._inflate64'

Related issue

To Reproduce

Steps to reproduce the behavior:
(example)

  1. install pip install py7zr (0.20.2 - 0.20.7)
  2. Run following code with python3.
import py7zr
with py7zr.SevenZipFile(r'C:\temp\test.7z', 'w') as archive:  #and zip
    archive.write(r'C:\temp\asd.txt')
    #archive.close()

Environment (please complete the following information):

  • OS: Windows 10x64 Pro 22H2
  • Python 3.9.7 (tags/v3.9.7:1016ef3, Aug 30 2021, 20:19:38) [MSC v.1929 64 bit (AMD64)]
  • py7zr version: (0.20.7, 0.20.6, 0.20.5, 0.20.4, 0.20.2)

Test data(please attach in the report):
1:
`Traceback (most recent call last):

File C:\Python_3.9.7x64\Lib\site-packages\bcj_init_.py:12
from ._bcj import (

ModuleNotFoundError: No module named 'bcj._bcj'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File C:\Python_3.9.7x64\Lib\site-packages\bcj_init_.py:28
from ._bcjfilter import (

ImportError: cannot import name 'IA64Decoder' from 'bcj._bcjfilter' (C:\Python_3.9.7x64\Lib\site-packages\bcj_bcjfilter.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File C:\Program Files\Spyder\pkgs\spyder_kernels\py3compat.py:356 in compat_exec
exec(code, globals, locals)

File z:\project_py\createZip.py:8
import py7zr

File C:\Python_3.9.7x64\Lib\site-packages\py7zr_init_.py:45
from py7zr.py7zr import ArchiveInfo, FileInfo, SevenZipFile, is_7zfile, pack_7zarchive, unpack_7zarchive

File C:\Python_3.9.7x64\Lib\site-packages\py7zr\py7zr.py:44
from py7zr.archiveinfo import Folder, Header, SignatureHeader

File C:\Python_3.9.7x64\Lib\site-packages\py7zr\archiveinfo.py:36
from py7zr.compressor import SevenZipCompressor, SevenZipDecompressor

File C:\Python_3.9.7x64\Lib\site-packages\py7zr\compressor.py:33
import bcj

File C:\Python_3.9.7x64\Lib\site-packages\bcj_init_.py:44
raise ImportError(msg)

ImportError: pybcj module: Neither C implementation nor Python implementation can be imported.`


2:
(pip install bcj-cffi)

`Traceback (most recent call last):

File C:\Program Files\Spyder\pkgs\spyder_kernels\py3compat.py:356 in compat_exec
exec(code, globals, locals)

File z:\project_py\createZip.py:8
import py7zr

File C:\Python_3.9.7x64\Lib\site-packages\py7zr_init_.py:45
from py7zr.py7zr import ArchiveInfo, FileInfo, SevenZipFile, is_7zfile, pack_7zarchive, unpack_7zarchive

File C:\Python_3.9.7x64\Lib\site-packages\py7zr\py7zr.py:44
from py7zr.archiveinfo import Folder, Header, SignatureHeader

File C:\Python_3.9.7x64\Lib\site-packages\py7zr\archiveinfo.py:36
from py7zr.compressor import SevenZipCompressor, SevenZipDecompressor

File C:\Python_3.9.7x64\Lib\site-packages\py7zr\compressor.py:33
import inflate64

File C:\Python_3.9.7x64\Lib\site-packages\inflate64_init_.py:6
from ._inflate64 import Deflater, Inflater # noqa

ModuleNotFoundError: No module named 'inflate64._inflate64'`

Additional context

Updated Python to 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]. Now it works without errors.

I've put a test case reproduced from @izhgtumekhanik reported here. It works well on Python 3.8, 3.9, 3.10, 3.11 and 3.12 on Windows. Are there any conditions or causes that lead the error? @