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

iMath redstone-cold at 163.com
Mon Aug 13 07:51:17 EDT 2018


The same question also posted here
https://stackoverflow.com/questions/51820473/right-way-to-use-zipimport-zipimport-zipimporterror-not-a-zip-file

I have managed to use [this module][1] without installation - just import it from path to use , 

    import sys
    url = 'https://example.com'
    sys.path.insert(0, r'C:\Users\i\Downloads\you-get-0.4.1128\src')  # 
    from you_get import common
    common.any_download(url, info_only=True)#NoneType

It seems possible in Python to use `zipimport` to directly use the zip archive of the module without extraction, I wonder what is the right way to use `zipimport`, a simple trying like the following just gives the exception . I downloaded the file from [here][2] , the file `C:\Users\i\Downloads\you-get-0.4.1128.zip` does exist and isn't corrupted.

    >>> import zipimport
    >>> zipimport.zipimporter(r'C:\Users\i\Downloads\you-get-0.4.1128.zip')
    Traceback (most recent call last):
      File "<pyshell#1>", line 1, in <module>
        zipimport.zipimporter(r'C:\Users\i\Downloads\you-get-0.4.1128.zip')
    zipimport.ZipImportError: not a Zip file: 'C:\\Users\\i\\Downloads\\you-get-0.4.1128.zip'
    >>> 


  [1]: https://github.com/soimort/you-get/releases
  [2]: https://github.com/soimort/you-get/archive/v0.4.1128.zip



More information about the Python-list mailing list