安裝PIL遇到的問題


配置:Win7 64位
不過折騰到最后,沒有使用PIL,官方的PIL很久木有更新了,換了Pillow,是PIL的衍生吧,一直有更新,但是兩者不可在同一環境共存。
1 Python version 2.7 required,which was not found in the registry.
官方下載 http://www.pythonware.com/products/pil/,安裝PIL,出現如下錯誤提示,Python version 2.7 required,which was not found in the registry.

解決方案:

register.py
 1 import sys
 2   
 3 from _winreg import *
 4   
 5 # tweak as necessary
 6 version = sys.version[:3]
 7 installpath = sys.prefix
 8   
 9 regpath = "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version)
10 installkey = "InstallPath"
11 pythonkey = "PythonPath"
12 pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % (
13     installpath, installpath, installpath
14 )
15   
16 def RegisterPy():
17     try:
18         reg = OpenKey(HKEY_CURRENT_USER, regpath)
19     except EnvironmentError as e:
20         try:
21             reg = CreateKey(HKEY_CURRENT_USER, regpath)
22             SetValue(reg, installkey, REG_SZ, installpath)
23             SetValue(reg, pythonkey, REG_SZ, pythonpath)
24             CloseKey(reg)
25         except:
26             print "*** Unable to register!"
27             return
28         print "--- Python", version, "is now registered!"
29         return
30     if (QueryValue(reg, installkey) == installpath and
31         QueryValue(reg, pythonkey) == pythonpath):
32         CloseKey(reg)
33         print "=== Python", version, "is already registered!"
34         return
35     CloseKey(reg)
36     print "*** Unable to register!"
37     print "*** You probably have another Python installation!"
38 
39 if __name__ == "__main__":
40     RegisterPy()
將如上文件執行,進行注冊,之后再嘗試安裝,成功。
 
2 DLL load failed:%1不是有效的Win32應用程序
但是之后在使用_imaging模塊時又報錯:
DLL load failed:%1不是有效的Win32應用程序
是因為安裝的Python是64位,PIL卻是32位,而官方發布的只有32位,找個非官方的64位安裝。
 
3 如何卸載目前安裝的PIL
在PIL安裝路徑下看到RemovePIL.exe文件,執行失敗,提示:This program is normally started by Windoows。
在該路徑中可看到PIL-wininst.log,里面有記錄卸載的命令,根據提示執行卸載命令即可。
 

原因:

python有64位的,pil官方只有32位的。安裝時會提示找不到python的安裝路徑。

64位Win7下無法安裝PIL庫的原因

PIL官方http://www.pythonware.com/products/pil/提供的PIL二進制安裝庫都是32位的。

64位程序和32位程序檢測注冊表的位置是不一樣的:

64-bit: HKEY_LOCAL_MACHINESOFTWAREPython

32-bit: HKEY_LOCAL_MACHINESOFTWAREWow6432NodePython

我安裝的是Python2.7 x64版,所以相關信息是在 HKEY_LOCAL_MACHINESOFTWAREPython下面,32位程序在HKEY_LOCAL_MACHINESOFTWAREWow6432NodePython 下面找Python安裝信息,肯定是找不到了。

解決:

幸好有人提供了非官方的64位庫(官方源碼編譯版)。

http://www.lfd.uci.edu/~gohlke/pythonlibs/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM