3

I am working on a Python project that requires PIL to show images. However, the computers that I am working on often do not allow me to install things, and have a very bare bones python setup. For this reason, most of the modules that I need I simply place in the same directory as my python files.

I tried doing the same with PIL. I downloaded the pillow source, and copied the PIL folder into my project. I was then able to run "import PIL" with no problems. However, when I then tried to run "from PIL import Image" I get the error: "The _Imaging C module is not installed". From other searches I think that installing Pillow properly would fix this problem, however I would like PIL to be more portable, and not require an instillation.

Any ideas would be great. Thanks in advance.

Inazuma
  • 178
  • 3
  • 13
  • 1
    If you are having trouble building the `.egg` file for `PIL`, alternatively you could download `Pillow`'s `.egg` file pre-made [here](https://pypi.python.org/pypi/Pillow/2.7.0) – Gillespie Feb 11 '15 at 20:29

1 Answers1

4

One solution is bundle PIL in with the script in .egg form. Then, you can import PIL directly from the .egg instead of having to install it:

How to create Python egg file

The basic process is as follows:

How to create egg:

  1. Edit PIL's setup.py to include from setuptools import setup instead of normal setup import
  2. Run python setup.py bdist_egg
  3. Egg will be inside of dist/

How to import egg:

Copy .egg file to script's directory and import desired modules:

import os
import sys

DIR = os.path.dirname(__file__)
sys.path.append(os.path.join(DIR, "./path/to/PIL.egg"))

#You can now import from PIL normally:
from PIL import Image
Community
  • 1
  • 1
Gillespie
  • 5,780
  • 3
  • 32
  • 54
  • 1
    I tried doing this, using the pillow egg downloaded from PyPi. However, when using your script, I got the following error: File "C:\Users\USER\Documents\Python\PIL test\p import.py", line 8, in from PIL import Image File pil egg file, line 63, in from PIL import _imaging as core File pil egg file, line 7, in File pil egg file, line 6, in __bootstrap__ ImportError: DLL load failed: %1 is not a valid Win32 application. – Inazuma Feb 11 '15 at 20:43