How to extract a zip file in Python 2.7 / ImageJ / Jython

Assumptions and what I want to achieve

I am writing code in Python2.7(Jython) because I am using ImageJ.

I want to extract the zip file in Python 2.7, but I can’t do it.

I have a zip file called RoiSet.zip in a folder “OutletHDD” and I want to unzip it to a folder " hoge".

Problems and error messages encountered

Started ver2.py at Wed Dec 16 21:34:19 JST 2020
Traceback (most recent call last):
  File "C:\Users\For  Programming\Documents\Python Scripts\OutletHDD\ver2.py", line 12, in <module>
    imp = IJ.openImage(PICPATH)
  File "C:\Users\FORPRO~1\Desktop\Fiji.app\jars\jython-slim-2.7.2.jar\Lib\zipfile.py", line 1038, in extractall
  File "C:\Users\FORPRO~1\Desktop\Fiji.app\jars\jython-slim-2.7.2.jar\Lib\zipfile.py", line 1026, in extract
  File "C:\Users\FORPRO~1\Desktop\Fiji.app\jars\jython-slim-2.7.2.jar\Lib\zipfile.py", line 1059, in _extract_member
TypeError: character mapping must return integer, None or unicode

	at org.python.core.Py.TypeError(Py.java:236)
	at org.python.modules._codecs.translateCharmap(_codecs.java:446)
	at org.python.core.PyUnicode.unicode_translate(PyUnicode.java:2126)
	at org.python.core.PyUnicode$unicode_translate_exposer.__call__(Unknown Source)
	at org.python.core.PyObject.__call__(PyObject.java:465)
	at zipfile$py._extract_member$45(C:/Users/FORPRO~1/Desktop/Fiji.app/jars/jython-slim-2.7.2.jar/Lib/zipfile.py:1081)
	at zipfile$py.call_function(C:/Users/FORPRO~1/Desktop/Fiji.app/jars/jython-slim-2.7.2.jar/Lib/zipfile.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:173)
	at org.python.core.PyBaseCode.call(PyBaseCode.java:187)
	at org.python.core.PyFunction.__call__(PyFunction.java:449)
	at org.python.core.PyMethod.__call__(PyMethod.java:171)
	at zipfile$py.extract$43(C:/Users/FORPRO~1/Desktop/Fiji.app/jars/jython-slim-2.7.2.jar/Lib/zipfile.py:1026)
	at zipfile$py.call_function(C:/Users/FORPRO~1/Desktop/Fiji.app/jars/jython-slim-2.7.2.jar/Lib/zipfile.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:173)
	at org.python.core.PyBaseCode.call(PyBaseCode.java:187)
	at org.python.core.PyFunction.__call__(PyFunction.java:449)
	at org.python.core.PyMethod.__call__(PyMethod.java:171)
	at zipfile$py.extractall$44(C:/Users/FORPRO~1/Desktop/Fiji.app/jars/jython-slim-2.7.2.jar/Lib/zipfile.py:1037)
	at zipfile$py.call_function(C:/Users/FORPRO~1/Desktop/Fiji.app/jars/jython-slim-2.7.2.jar/Lib/zipfile.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:173)
	at org.python.core.PyBaseCode.call(PyBaseCode.java:306)
	at org.python.core.PyBaseCode.call(PyBaseCode.java:141)
	at org.python.core.PyFunction.__call__(PyFunction.java:426)
	at org.python.core.PyMethod.__call__(PyMethod.java:141)
	at org.python.pycode._pyx23.f$0(C:/Users/For  Programming/Documents/Python Scripts/OutletHDD/ver2.py:13)
	at org.python.pycode._pyx23.call_function(C:/Users/For  Programming/Documents/Python Scripts/OutletHDD/ver2.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:173)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.Py.runCode(Py.java:1687)
	at org.python.core.__builtin__.eval(__builtin__.java:497)
	at org.python.core.__builtin__.eval(__builtin__.java:501)
	at org.python.util.PythonInterpreter.eval(PythonInterpreter.java:255)
	at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:57)
	at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:31)
	at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
	at org.scijava.script.ScriptModule.run(ScriptModule.java:157)
	at org.scijava.module.ModuleRunner.run(ModuleRunner.java:165)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:124)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:63)
	at org.scijava.thread.DefaultThreadService.lambda$wrap$2(DefaultThreadService.java:225)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Started New_.py at Wed Dec 16 21:37:42 JST 2020

Source code.

import zipfile
from ij.plugin.frame import RoiManager
from ij.process import ImageProcessor
zippath = "C:\Users\For Programming\Documents\Python Scripts\OutletHDD\RoiSet.zip"


ZipObj = zipfile.ZipFile(zippath) 
ZipObj.extractall("C:\Users\For Programming\Documents\Python Scripts\OutletHDD\hoge") #Unzip and move the Zip file
ZipObj.close() 

What I tried

I thought it might be a bug with Unicode type, str type, and I want to try to do str(), Unicode(), etc. but it didn’t work.

Additional information (FW/tool versions, etc.)

I write the code from japan(may be it related to Character code)

Windows10 64bit

2.7.2 (v2.7.2:925a3cc3b49d, Mar 21 2020, 10:12:24)
[Java HotSpot™ 64-Bit Server VM (Oracle Corporation)]

I want to get any information about this , If my information lack, please tell me

I think this problem is caused by some environmental factors (Windows or not, ENVIRONMENT PATH, etc…)

I test to extract a zip file which not roifile(not .roi), the code work fine.

I don’t understand more and more.