문제

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). 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.

It depends on os, shutil, string, sys, tkinter, webbrowser, PIL, ftplib, and glob.

It seems as though all of the dependencies got imported when I ran cx_freeze on it, except for PIL. I have never used cx_freeze before, so I could be doing something wrong but it doesn't seem like it. Running the program from the unfrozen .py script works just fine.

Here's the error message I receive when trying to use a PIL command:

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).

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. 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:

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. Other modules seem to work just fine like shutil, os, and sys, for example.

도움이 되었습니까?

해결책

I think your main problem may be that the Python Imaging Library (PIL) does not yet support Python 3.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.

This question has an answer which details unofficial ports of PIL for Python 3.x which might be worth a try.

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.

다른 팁

In the past I have found cx_Freeze to have issues pulling in the correct DLLs under Windows.

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. 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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top