Python3: lzma unpack .7z file

后端 未结 3 898
逝去的感伤
逝去的感伤 2020-12-06 04:55

I would like to unpack a .7z file. According to this question I can use the lzma package to do this.

I was expecting something like

import lzma
#...         


        
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-06 05:12

    Credits for this solution go to Matt Dnv in this answer:

    I was not able to make the given answers work. Most solutions for unpacking a 7z file in python used 7zip for which I was not able to find a reliable portable version that I could curl.

    Hence here is a solution to unpack a .7z file in a python 3.6 environment in Anaconda prompt 4.8.2. First I had to install 2 packages:

    pip install pyunpack
    pip install patool
    

    Next I was able to unpack a 7zip filed named test.7z which was located in the same directory as this example.py script, to a folder named: output (also located in the same directory as this example.py script). The code to unpack the test.7z file can be:

    from pyunpack import Archive
    Archive('test.7z').extractall('./output')
    

提交回复
热议问题