1

I've installed Python 2.7 alongside Python 2.4 as instructed here. When running a tests through Mac OSX Terminal connecting to the Server to confirm that the install is working I execute this test:

import Image
img = Image.open("/directory/image.jpg")
img.load()
print img

Result:

<PixelAccess object at 0x2b97d4c25110>
<JpegImagePlugin.JpegImageFile image mode=RGB size=75x75 at 0xFEF4050>

However, when executing this using PHP's exec() or through a Coda extension Run Script for Coda, I get the error:

ImportError: No module named Image

I've also tried from PIL import Image which does not make a difference. Something else to note is that when I check to make sure that the support is there I get this which indicates that the proper image support is available:

*** TKINTER support not available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
--- FREETYPE2 support available
*** LITTLECMS support not available

Question: Any ideas on how to fix this?

stwhite
  • 3,156
  • 4
  • 37
  • 70
  • total longshot, but why don't you try uninstalling PIL and installing [PILLOW](https://pypi.python.org/pypi/Pillow/2.2.1)? Then you can actually do `import PIL.Image` etc. instead of the silly `import Image` thing that PIL makes you do. I doubt it will fix the import problem, but it wouldn't hurt. – KobeJohn Dec 13 '13 at 14:27

3 Answers3

0

PHP is running the wrong version of Python. Specify the full path to the python executable.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
  • I thought that might be the problem, however I ran `import sys` then `print sys.version_info` which returns 2.7.1: `sys.version_info(major=2, minor=7, micro=1, releaselevel='final', serial=0)` – stwhite May 30 '12 at 06:50
0

@stwhite I suggest you to use virtualenv (http://www.virtualenv.org/en/latest/index.html) for multiple projects to live in their own environments.

Usefull wrapper for virtualenv http://www.doughellmann.com/projects/virtualenvwrapper/

My own projects live in their own virtualenvs and its really awesome.

Here is the question about creating virtualenv with specific python version Use different Python version with virtualenv

Note May be you'll have problems when installing PIL into the virtualenv

Solution

First install XCode with gcc support,
deactivate <virtualenv_name>
cd ../ (virtualenvs root)
pip install -E <virtualenv_name/> PIL

Hope this will work for you too,

Thanks,

Sultan

Community
  • 1
  • 1
sultan
  • 5,978
  • 14
  • 59
  • 103
  • Though this could be an option to starting over, I'm hoping there is a solution to fix the current issue without redoing the whole setup. – stwhite May 30 '12 at 07:36
0

Make sure your PYTHONPATH is correct when running via exec() call.

Import sys
print sys.path
sys.path.append ("<path of Image>")

You can also load the module dynamically, at runtime to ensure its available, provided its available in the standard location.

blispr
  • 883
  • 5
  • 10