Python安装PIL遇到‘Could not find a version that satisfies the requirement PIL’

时间:2022-04-29 17:07:55

问题重现:

PS C:\Windows\system32> pip install PIL

Collecting PIL
  Could not find a version that satisfies the requirement PIL (from versions: )
  Some externally hosted files were ignored as access to them may be unreliable (use --allow-external PIL to allow).

No matching distribution found for PIL

原因:

<p class="cye-lm-tag" style="border: 0px rgb(51, 58, 51); padding-bottom: 0px; margin-top: 0px; margin-bottom: 1em; clear: both; padding-top: 0px;">This is due to changes in the new version of Pip. Run <span style="font-family:Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, sans-serif;font-size:14px;color:#333333;"><span style="line-height: 19px; white-space: pre-wrap; background-color: rgb(204, 232, 207); border-color: rgb(51, 58, 51); padding: 1px 5px;">pip --version</span></span> and I'm willing to bet you are running <span style="border: 0px; padding: 0px; margin: 0px;">1.5</span>. See the changelog <a target=_blank target="_blank" href="https://github.com/pypa/pip/blob/c2361e72da2c31a3596d49dc5fccb7d2bdb8c032/CHANGES.txt#L12-L15" style="border: 0px; padding: 0px; margin: 0px;">here</a>. This new default behavior enhances security. In PIL's case, the file you are installing actually comes from <span style="border: 0px; padding: 0px; margin: 0px;">effbot.org</span> (thus <span style="font-family:Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, sans-serif;font-size:14px;color:#333333;"><span style="line-height: 19px; white-space: pre-wrap; background-color: rgb(238, 238, 238); padding: 1px 5px;">--allow-external</span></span>) and PyPi doesn't have a checksum to guarantee validity (thus <span style="font-family:Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, sans-serif;font-size:14px;color:#333333;"><span style="line-height: 19px; white-space: pre-wrap; background-color: rgb(238, 238, 238); padding: 1px 5px;">--allow-unverified</span></span>).</p><p class="cye-lm-tag" style="border: 0px rgb(51, 58, 51); padding-bottom: 0px; margin-top: 0px; margin-bottom: 1em; clear: both; padding-top: 0px;">Also, you might consider using the <a target=_blank target="_blank" href="https://pypi.python.org/pypi/Pillow/" style="border: 0px; padding: 0px; margin: 0px;">Pillow</a> replacement to PIL.</p>


加上--allow-external PIL --allow-unverified PIL选项

PS C:\Windows\system32> pip install PIL --allow-external PIL --allow-unverified PIL
Collecting PIL
  PIL is potentially insecure and unverifiable.
  Downloading http://effbot.org/media/downloads/PIL-1.1.7.tar.gz (506kB)
    100% |████████████████████████████████| 507kB 2.6MB/s
Building wheels for collected packages: PIL
  Running setup.py bdist_wheel for PIL
  Complete output from command C:\Python27\python.exe -c "import setuptools;__file__='c:\\users\\jay\\appdata\\local\\te
mp\\pip-build-ccr0hh\\PIL\\setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" bdist
_wheel -d c:\users\jay\appdata\local\temp\tmpd1frnspip-wheel-:
  WARNING: '' not a valid package name; please use only.-separated package names in setup.py
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build\lib.win-amd64-2.7
  copying PIL\ArgImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\BdfFontFile.py -> build\lib.win-amd64-2.7
  copying PIL\BmpImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\BufrStubImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\ContainerIO.py -> build\lib.win-amd64-2.7
  copying PIL\CurImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\DcxImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\EpsImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\ExifTags.py -> build\lib.win-amd64-2.7
  copying PIL\FitsStubImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\FliImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\FontFile.py -> build\lib.win-amd64-2.7
  copying PIL\FpxImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\GbrImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\GdImageFile.py -> build\lib.win-amd64-2.7
  copying PIL\GifImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\GimpGradientFile.py -> build\lib.win-amd64-2.7
  copying PIL\GimpPaletteFile.py -> build\lib.win-amd64-2.7
  copying PIL\GribStubImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\Hdf5StubImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\IcnsImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\IcoImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\Image.py -> build\lib.win-amd64-2.7
  copying PIL\ImageChops.py -> build\lib.win-amd64-2.7
  copying PIL\ImageCms.py -> build\lib.win-amd64-2.7
  copying PIL\ImageColor.py -> build\lib.win-amd64-2.7
  copying PIL\ImageDraw.py -> build\lib.win-amd64-2.7
  copying PIL\ImageDraw2.py -> build\lib.win-amd64-2.7
  copying PIL\ImageEnhance.py -> build\lib.win-amd64-2.7
  copying PIL\ImageFile.py -> build\lib.win-amd64-2.7
  copying PIL\ImageFileIO.py -> build\lib.win-amd64-2.7
  copying PIL\ImageFilter.py -> build\lib.win-amd64-2.7
  copying PIL\ImageFont.py -> build\lib.win-amd64-2.7
  copying PIL\ImageGL.py -> build\lib.win-amd64-2.7
  copying PIL\ImageGrab.py -> build\lib.win-amd64-2.7
  copying PIL\ImageMath.py -> build\lib.win-amd64-2.7
  copying PIL\ImageMode.py -> build\lib.win-amd64-2.7
  copying PIL\ImageOps.py -> build\lib.win-amd64-2.7
  copying PIL\ImagePalette.py -> build\lib.win-amd64-2.7
  copying PIL\ImagePath.py -> build\lib.win-amd64-2.7
  copying PIL\ImageQt.py -> build\lib.win-amd64-2.7
  copying PIL\ImageSequence.py -> build\lib.win-amd64-2.7
  copying PIL\ImageShow.py -> build\lib.win-amd64-2.7
  copying PIL\ImageStat.py -> build\lib.win-amd64-2.7
  copying PIL\ImageTk.py -> build\lib.win-amd64-2.7
  copying PIL\ImageTransform.py -> build\lib.win-amd64-2.7
  copying PIL\ImageWin.py -> build\lib.win-amd64-2.7
  copying PIL\ImImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\ImtImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\IptcImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\JpegImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\McIdasImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\MicImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\MpegImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\MspImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\OleFileIO.py -> build\lib.win-amd64-2.7
  copying PIL\PaletteFile.py -> build\lib.win-amd64-2.7
  copying PIL\PalmImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\PcdImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\PcfFontFile.py -> build\lib.win-amd64-2.7
  copying PIL\PcxImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\PdfImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\PixarImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\PngImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\PpmImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\PsdImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\PSDraw.py -> build\lib.win-amd64-2.7
  copying PIL\SgiImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\SpiderImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\SunImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\TarIO.py -> build\lib.win-amd64-2.7
  copying PIL\TgaImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\TiffImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\TiffTags.py -> build\lib.win-amd64-2.7
  copying PIL\WalImageFile.py -> build\lib.win-amd64-2.7
  copying PIL\WmfImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\XbmImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\XpmImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\XVThumbImagePlugin.py -> build\lib.win-amd64-2.7
  copying PIL\__init__.py -> build\lib.win-amd64-2.7
  running build_ext
  building '_imaging' extension
  error: Microsoft Visual C++ 9.0 is required (Unable to find vcvarsall.bat). Get it fromhttp://aka.ms/vcpython27


  ----------------------------------------
  Failed building wheel for PIL
Failed to build PIL
Installing collected packages: PIL
  Running setup.py install for PIL
    Complete output from command C:\Python27\python.exe -c "import setuptools, tokenize;__file__='c:\\users\\jay\\appdat
a\\local\\temp\\pip-build-ccr0hh\\PIL\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('
\r\n', '\n'), __file__, 'exec'))" install --record c:\users\jay\appdata\local\temp\pip-7gvtci-record\install-record.txt
--single-version-externally-managed --compile:
    WARNING: '' not a valid package name; please use only.-separated package names in setup.py
    running install
    running build
    running build_py
    running build_ext
    building '_imaging' extension
    error: Microsoft Visual C++ 9.0 is required (Unable to find vcvarsall.bat). Get it from http://aka.ms/vcpython27


    ----------------------------------------
Command "C:\Python27\python.exe -c "import setuptools, tokenize;__file__='c:\\users\\jay\\appdata\\local\\temp\\pip-buil
d-ccr0hh\\PIL\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__,
'exec'))" install --record c:\users\jay\appdata\local\temp\pip-7gvtci-record\install-record.txt --single-version-externa
lly-managed --compile" failed with error code 1 in c:\users\jay\appdata\local\temp\pip-build-ccr0hh\PIL

按照要求去M$下载完再重新安装,成功。

PS C:\Windows\system32> pip install PIL --allow-external PIL --allow-unverified PIL
Collecting PIL
  PIL is potentially insecure and unverifiable.
  Downloading http://effbot.org/media/downloads/PIL-1.1.7.tar.gz (506kB)
    100% |████████████████████████████████| 507kB 3.4MB/s
Building wheels for collected packages: PIL
  Running setup.py bdist_wheel for PIL
  Stored in directory: C:\Users\Jay\AppData\Local\pip\Cache\wheels\ba\31\4a\9a5596f0640c9099a4302a71b56b7581e16e0d0b5a8f
30ce3e
Successfully built PIL
Installing collected packages: PIL
Successfully installed PIL-1.1.7
PS C:\Windows\system32> pip freeze
PIL==1.1.7
sinaweibopy==1.1.3
wheel==0.24.0