简体   繁体   English

使用Python 3为Windows用户创建程序,不能使用PIL?

[英]Creating a program in Python 3 for Windows users, cannot use PIL?

I wrote a fairly simple GUI program to automate a few processes for Windows users in Python (as it is the only programming language I am somewhat familiar with that will run on Windows). 我写了一个相当简单的GUI程序,用Python为Windows用户自动化一些过程(因为这是我有点熟悉的唯一一种编程语言,它将在Windows上运行)。 I would ideally not want the user to have to run an install program on their machine, as my plan is for it to run self-contained in a USB drive. 理想情况下,我不希望用户在其计算机上运行安装程序,因为我的计划是使其在USB驱动器中独立运行。

It depends on os, shutil, string, sys, tkinter, webbrowser, PIL, ftplib, and glob. 它取决于os,shutil,string,sys,tkinter,webbrowser,PIL,ftplib和glob。

It seems as though all of the dependencies got imported when I ran cx_freeze on it, except for PIL. 我似乎在对它运行cx_freeze时都导入了所有依赖项,除了PIL。 I have never used cx_freeze before, so I could be doing something wrong but it doesn't seem like it. 我以前从未使用过cx_freeze,所以我可能做错了什么,但看起来好像不是。 Running the program from the unfrozen .py script works just fine. 从未冻结的.py脚本运行程序就可以了。

Here's the error message I receive when trying to use a PIL command: 这是尝试使用PIL命令时收到的错误消息:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python32\lib\tkinter\__init__.py", line 1399, in __call__
    return self.func(*args)
  File "E:\AlbumUploader.py", line 143, in OnButton2Click
    img.thumbnail(size, Image.ANTIALIAS)
  File "C:\Python32\lib\site-packages\PIL\Image.py", line 1573, in thumbnail
    self.load()
  File "C:\Python32\lib\site-packages\PIL\ImageFile.py", line 168, in load
    self.load_prepare()
  File "C:\Python32\lib\site-packages\PIL\ImageFile.py", line 234, in load_prepare
    self.im = Image.core.new(self.mode, self.size)
  File "C:\Python32\lib\site-packages\PIL\Image.py", line 39, in __getattr__
    raise ImportError("The _imaging C module is not installed")
ImportError: The _imaging C module is not installed

Thanks for any help you can provide. 感谢您的任何帮助,您可以提供。 I see that it's still referencing C:\\Python32 which could be part of the problem, because it shouldn't be (if I'm not mistaken). 我看到它仍在引用C:\\ Python32,这可能是问题的一部分,因为它不应该(如果我没记错的话)。

Update: 更新:

I looked at the PIL FAQ and it seems like the gist of that answer is that I need to make sure my sys.path list is correct. 我查看了PIL常见问题解答,似乎该答案的要点是我需要确保sys.path列表正确。 I basically grabbed all the Python files for Windows and included it in the USB drive which I am trying to use to contain everything, and set my path like so: 我基本上抓取了Windows的所有Python文件,并将其包含在USB驱动器中,我试图使用它包含所有内容,并按以下方式设置路径:

program_dir = os.path.split(sys.argv[0])[0]
sys.path = [program_dir]
sys.path.append(program_dir + os.sep + 'Lib')
sys.path.append(program_dir + os.sep + 'Lib' + os.sep + 'site-packages')
sys.path.append(program_dir + os.sep + 'Lib' + os.sep + 'site-packages' + os.sep + 'PIL')
sys.path.append(program_dir + os.sep + 'DLLs')

All the paths seem correct, but for some reason I am still getting the same error. 所有路径似乎都是正确的,但是由于某种原因,我仍然遇到相同的错误。 When I run the .py file everything works 100%, but this seems to break it somehow. 当我运行.py文件时,所有内容都可以100%运行,但这似乎以某种方式破坏了它。 Other modules seem to work just fine like shutil, os, and sys, for example. 例如,其他模块似乎也可以正常运行,例如shutil,os和sys。

I think your main problem may be that the Python Imaging Library (PIL) does not yet support Python 3.x. 我认为您的主要问题可能是Python Imaging Library(PIL)尚不支持Python3.x。

If you look at the PIL downloads page you'll see that there are Windows downloads for Python 2.4, 2.5, 2.6 and 2.7 but nothing for Python 3.x. 如果您查看“ PIL下载”页面,您会看到针对Python 2.4、2.5、2.6和2.7的Windows下载,而对于Python 3.x没有。

This question has an answer which details unofficial ports of PIL for Python 3.x which might be worth a try. 这个问题的答案详细说明了Python 3.x的非官方PIL端口,可能值得一试。

If that works you could take a look at the first question on the PIL FAQ which is about the "The _imaging C module is not installed" error and lists various things you can do to identify the problem. 如果可行,您可以查看PIL FAQ上的第一个问题,该问题与“未安装_imaging C模块”错误有关,并列出了您可以用来确定问题的各种措施。

In the past I have found cx_Freeze to have issues pulling in the correct DLLs under Windows. 在过去,我发现cx_Freeze在Windows下提取正确的DLL时遇到问题。

I used Process Explorer to track down what DLLs were being looked for, but not found, and then added them to the project manually, and this got it working. 我使用Process Explorer来查找正在寻找但找不到的DLL,然后将它们手动添加到项目中,这使它起作用。 As it would do the same for any file, I imagine the same could be done in your case. 就像对任何文件一样,我想在您的情况下也可以这样做。

This was for my usage with PySFML, so your mileage may vary. 这是我在PySFML中使用的方式,因此您的工作量可能会有所不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM