right way to use zipimport, zipimport.ZipImportError: not a Zip file

iMath redstone-cold at 163.com
Tue Aug 14 03:34:17 EDT 2018


I think someone gives the true reason caused the exception here
https://stackoverflow.com/a/51821910/1485853

Thanks to his  explanation , I extracted the zip archive and then add the extracted to a zip archive using Bandizip, this time `zipimport.zipimporter(r'C:\Users\i\Downloads\you-get-0.4.1128.zip') ` doesn't give the exception , but still cannot import the module, even adding the  `.zip`  file to  `sys.path`,

    >>> import sys
    >>> sys.path.insert(0, r'C:\Users\i\Downloads\you-get-0.4.1128.zip\you-get-0.4.1128\src')
    >>> from you_get import common
    Traceback (most recent call last):
      File "<pyshell#17>", line 1, in <module>
        from you_get import common
    ModuleNotFoundError: No module named 'you_get'
    >>> 


    >>> import zipimport
    >>> z=zipimport.zipimporter(r'C:\Users\i\Downloads\you-get-0.4.1128.zip\you-get-0.4.1128\src')
    >>> z
    <zipimporter object "C:\Users\i\Downloads\you-get-0.4.1128.zip\you-get-0.4.1128\src\">
    >>> z.load_module('you_get.common')
    Traceback (most recent call last):
      File "<pyshell#9>", line 1, in <module>
        z.load_module('you_get.common')
    zipimport.ZipImportError: can't find module 'you_get.common'
    >>> z.load_module('you_get')
    Traceback (most recent call last):
      File "<pyshell#10>", line 1, in <module>
        z.load_module('you_get')
    zipimport.ZipImportError: can't find module 'you_get'


What I actually want to do is to use the module in  a pyinstaller frozen application  , I also need to upgrade  the module  to latest version whenever needed , I cannot find a solution yet.



More information about the Python-list mailing list