1


I am writing a short script.py which will update archive.tar.
The tar archive's content is one single file: file.txt (Content: "Hello").
I am using 7za.exe which is the the command line version of 7zip to update file.txt with another file.txt (Content: "Hello world"). I am using the following command:

os.system("7za u archive.tar file.txt")

So far everything is working, however I would like to create an executable from the Python Script using PyInstaller, since not everyone using this script will have python installed.

My question: is there a way to merge both script.py and 7za.exe into one single .exe file? So far, I have not been able to find an answer.

cyberme0w
  • 39
  • 1
  • 8

1 Answers1

3

Why not simply using the ZipFile library?

This could be as simple as:

with ZipFile('spam.zip', 'w') as myzip:
    myzip.write('eggs.txt')

If you really want to use a third party then no, there is no simple way of doing what you want to do. The only "clean" way would be to pack your executables together by using an installer, like the ones you could create with Innosetup

NB: You should prefer the use of subprocess rather that os.system, see there https://docs.python.org/fr/3/library/subprocess.html#replacing-os-system

Update: For a tarfile, maybe these could help you:

Maybe you'll have to decompress / add / recompress, but you should be able to do it in memory.

olinox14
  • 6,177
  • 2
  • 22
  • 39
  • I am guessing ZipFile will not work, since my archive is a .tar and not a .zip. I have tried using tarfile, too, but there is no option to update a file inside the archive, only to create a new one. Even the bsdtar command on Windows 10 won't let me update files... Only way I managed to do it until now was with 7zip. I would prefer not to build an installer, and instead just keep it as an exe which can be passed around. And I made a note to change from os.system to subprocess when I get this problem solved ;) – cyberme0w Nov 20 '19 at 10:22
  • Ah yeah, my bad, I did not spot the .tar at first. See my updates – olinox14 Nov 20 '19 at 10:57