(disclaimer) I contribute to https://github.com/Changaco/python-libarchive-c and I maintain https://github.com/nexB/scancode-toolkit
Both contain a ctypes
binding for libarchive
, though ScanCode is for extraction only.
My answer here is for python-libarchive-c
, but ScanCode contains some of the DLL you are looking for so I am lacing in a bit of both.
To get python-libarchive-c
going on Windows you need a libarchive
DLL and its deps that can then be loaded.
There are no pre-built DLLs bundled in python-libarchive-c
but I have prebuilt Windows binaries for another project here:
https://github.com/nexB/scancode-toolkit/tree/develop/src/extractcode/bin/win-32/bin
The corresponding source code is there: https://github.com/nexB/scancode-thirdparty-src
And you have MinGW32
build instructions there if you want to rebuild from source yourself: https://github.com/nexB/scancode-thirdparty-src/blob/master/libarchive/build.sh#L47
In general to load a DLL from a path -- assuming that the var libarchive
contains the full path to that DLL -- use this:
lib = ctypes.CDLL(libarchive)
Now this is for Scancode. For python-libarchive-c
, you could try to set the LIBARCHIVE
variable to point the path of your DLL with:
set LIBARCHIVE="C:\.....\libarchive.dll"
Then start Python, import the library and use it.
NB: I did not test this (yet) , but this should work. IF not please file a bug.
I did not run any test on Python 3.4 either. I use primarily Python 2.7.
But the DLL and the code is not Python 2.7-specific at all.
FWIW, the way scancode loads the library is a tad more engaged since it can from the same code load DLLs Win/Linux/Mac for specific 32 or 64 bits archs using conventional locations. You can see the code in action there:
https://github.com/nexB/scancode-toolkit/blob/develop/src/extractcode/libarchive2.py#L64
ScanCode is NOT using python-libarchive-c
ATM yet but a different/custom ctypes binding focused on a more specific use case of extraction only. At least it gives you access to a Win DLL and its deps (or instruction a build them) and an example on how to load it correctly.
/HTH