Problem
I am using pyunpack to unpack a zip-file:
Archive(os.path.join(directory_zip, foldername + ".7z")).extractall(
data_path
)
However I run into the following error:
patool not found! Please install patool!
When checking, patool is installed in the global Python-environment. I double-checked that I am using the global Python interpreter and that all versions are compatible. I am also able to run patool from the CMD. Everything seems to work since patool.exe is added to the Windows PATH variable: C:\Users\user\AppData\Local\Programs\Python\Python310 is added to the PATH variable and in here patool.exe is located
Temporary Fix After further digging I found that the following in the init.py from pyunpack:
def _exepath(cmd: str) -> Optional[str]:
for p in os.environ["PATH"].split(os.pathsep):
fullp = os.path.join(p, cmd)
if os.access(fullp, os.X_OK):
return fullp
return None
def extractall_patool(self, directory: str, patool_path: Optional[str]) -> None:
log.debug("starting backend patool")
if not patool_path:
patool_path = _exepath("patool") # patool
if not patool_path:
raise ValueError("patool not found! Please install patool!")
So it seems like there is a check if the OS has rights to execute patool. This fails since the script checks for:
C:\Users\user\AppData\Local\Programs\Python\Python310\patool
while in reality (since I have file extensions enabled on Windows) the following is present:
C:\Users\user\AppData\Local\Programs\Python\Python310\patool.exe
I can make the code work and temporarily solve the issue by changing the following in the _init.py in pyunpack:
def extractall_patool(self, directory: str, patool_path: Optional[str]) -> None:
log.debug("starting backend patool")
if not patool_path:
patool_path = _exepath("patool.exe") # Changed from patool --> patool.exe
if not patool_path:
raise ValueError("patool not found! Please install patool!")
This works!
Questions
1. How should I solve this issue in a cleaner way?
2. How can I use my script in a virtual environment? I think in that case patool will be installed in the virtual environment and thus I need to add the path of the venv\scripts to the PATH variable of Windows? This seems cumbersome.
Thanks in advance!