C module image error in python PIL

I read other posts about the notorious _imaging C module error when installing PIL on Mac OS X, and none of the solutions provided anywhere, including the PIL FAQ, were helpful.

I have the latest versions of libjpeg and zlib recently installed from the source. I edited the Makefiles in each of them to include the -arch i386 parameter in the LD_FLAGS variable for 32-bit builds. PIL installs without any problems, and a brief installation description printed on the terminal suggests that support for JPEG, TIFF and PNG is fine. After that I try self-test:

new-host:Imaging-1.1.7 ely$ python selftest.py *** The _imaging C module is not installed 

This is usually seen for a number of reasons. Knowing more deeply, here I am trying to import _imaging directly into python.

 new-host:Imaging-1.1.7 ely$ python ActivePython 2.7.1.4 (ActiveState Software Inc.) based on Python 2.7.1 (r271:86832, Feb 7 2011, 11:33:10) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import PIL >>> import _imaging Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PIL/_imaging.so, 2): Symbol not found: _jpeg_resync_to_restart Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PIL/_imaging.so Expected in: dynamic lookup 

Here again, "Symbol not found: _jpeg_resync_to_restart" is known and common, and many people have suggested that this is due to the wrong path to libjpeg. I checked again and again, and I only have libjpeg (as well as zlib, etc.) installed in my home directory, all in separate folders, from the source, and all this is correctly marked in the setup.py file.

So, PIL should get jpeg support (and zlib, etc.) from the right places. All dependencies are installed. I see _imaging.so in my sys.path, but I still get this _jpeg_resync_to_restart error.

Are there any ideas that are not related to alternative posts? I spent ~ 7 hours reading and trying to find possible solutions from the posts in each forum that I can find.

+7
source share
9 answers

Since you tried several times to do this, I recommend running a few commands to clear the old elements first and start from the beginning.

I used jpeg v8c and Imaging 1.1.6 for Mac OS X, 10.6 and 10.7

get v8c from jpeg cd to jpeg directory.

 sudo make clean CC="gcc -arch i386" ./configure --enable-shared --enable-static make sudo make install 

get image I'm using 1.1.6

decompresses cd into image

 sudo rm -rf build vi setup.py JPEG_ROOT = libinclude("/usr/local/lib") sudo python setup.py install 

And it's simple

Run your python interpreter,

 import PIL import _imaging import Image 

if all is well, then all your settings.

Here is the full article on my Python 2.7 blog , OSX Lion, PIL and Imaging

+8
source

I ran into the same problem tonight on my Mac running Mac OS X v10.7.5, Python v2.7.1 with PIL Imaging 1.1.7 and jpeg 8d.


Summing up - the key to success in my case was:

 export ARCHFLAGS="-arch x86_64" 

None of the other answers solved the problem, I constantly get: The _imaging C module is not installed caused by: Symbol not found: _jpeg_resync_to_restart .

Digging here and there, finally I found a solution that at least works for me:

  • make sure that there are no obvious libjpeg libraries on the system: find / -iname "libjpe*" will tell you this. I temporarily changed the places where they exist, so no one could find them (especially / sw interacted with PIL in my case):

     mv opt opt-OFF mv sw sw-OFF 

These locations were created using the mac and fink ports - it should be warned that it is possible that FREETYPE2 cannot be found by PIL after this move - if you need it, just rename the libjpeg parts in these places.

  • in the PIL Imaging src directory, edit setup.py as described above to set JPEG_ROOT to / usr / local, try running:

     rm -rf build ; python setup.py build 2> /tmp/err > /tmp/log 

Check / tmp / log - you should not see JPEG support. Now you can go to the next step.

  • go to jpeg-8d src directory and run:

     export ARCHFLAGS="-arch x86_64" sudo make clean; CC="gcc -arch x86_64" ./configure --enable-shared --enable-static sudo make install 
  • go back to PIL Imaging, run the following commands:

     export ARCHFLAGS="-arch x86_64" sudo rm -rf build ; python setup.py build 2> /tmp/err > /tmp/log 

Check / tmp / log - now you will see "Availability of JPEG support", check / tmp / err - search for "jpeg" - if you see something like this: ld: warning: ignoring file /usr/local/lib/libjpeg.dylib, file was built for unsupported file format which is not the architecture being linked (i386) - then the flag flags (both of which were set by ARCHFLAGS and -arch) could not be called - investigate this case, it is crucial. If you do not see this, you are lucky and you can call the installation:

 export ARCHFLAGS="-arch x86_64" sudo rm -rf build ; sudo python setup.py install 

Check if your PIL works:

 python selftest.py 

or

 echo "import _imaging" | python && echo "Works" 

Hope this helps.

+4
source

The problem is that the _imaging module is linked to libjpeg dynamically, not statically. The libjpeg code is not directly included in the _imaging module. This means that your dynamic platform builder must be able to find libjpeg in order to load and link it. The MacOS knowledge is fuzzy here, but as I recall, its dynamic linker is called dyld , and its manpage can provide additional information about the options you have.

Normally, the dynamic linker of the platform will not search in your source directory for libraries, but you can say this, for example, by setting the environment variable DYLD_LIBRARY_PATH or editing the system-wide configuration (if there is one.) The setting of this environment variable should usually be done before you run Python, but maybe it doesn't work. You might want to embed the run-time search path in the _imaging extension, which is usually done by passing -rpath to the linker, but I don't know if this set of MacOS features offers. Finally, you can simply create libjpeg as a static library, not a shared one, and have a link to the _imaging module. This avoids the general library situation for libjpeg. For libjpeg, this is probably done using a configure script with --enable-static --disable-shared .

+2
source

I tried most of all these suggestions (as well as two other suggestions for blog links) on an old Mac 10.6 installation. None of them worked, but, nevertheless, read beyond the lines that I could correct. I added setup.py to find_include_file () in PIL right before returning 1 line "print os.path.join (directory, include)". This allowed me to keep track of which libjpeg PIL is being built against. Then I would create a PIL, find a link to libjpeg (various copies in / sw, / opt /, / usr / local / lib, ...) and delete that libjpeg (both header and lib files).

Finally, with a clean system, I built and installed the original libjpeg tarball, which I downloaded, and then built and installed PIL from the source. It worked. As a backup, you can always disable libjpeg by deleting the above files as described, or you can always return zero from the function described above to setup.py.

+2
source

Works well for me on Mountain Lion 10.8.2:

First step . Removing all jpeg packages. For MacPorts:

sudo port -f uninstall jpeg or sudo port -f uninstall jpeg @version_here

We need to uninstall all versions of jpeg!

Step Two Remove PIL: pip uninstall PIL

Step Three Install the jpeg package again. For MacPorts: sudo port install jpeg

Step Four Install PIL again: pip install PIL

 >>> import PIL >>> import _imaging 

No mistakes!


How to remove ALL jpeg packages?

 $ port installed | grep -i jpeg jpeg @8c_0 jpeg @9a_0 (active) $ sudo port -f uninstall jpeg @8c_0 $ sudo port -f uninstall jpeg @9a_0 

Do not worry about dependencies. Beacause we need to install the jpeg package again:

 $ sudo port install jpeg 
+1
source

I ran into all the bugs you guys mentioned. I broke down and just used virtualenv and installed Pillow instead. he worked:

 sudo pip install virtualenv virtualenv python_script && cd !$ . /activate/bin pip install Pillow 
+1
source

I had the same problem with Python 2.7 and OSX Lion, and basically the @ApPeL process was running and libjpeg and PIL were reinstalled. Probably libjpeg was installed correctly, and PIL seemed to find it correctly, but python -v worked, and then import _imaging always import _imaging this error:

ImportError: dlopen (/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PIL/_imaging.so, 2): Symbol not found: _jpeg_resync_to_restart

After installing and reinstalling libjpeg (version 8d) and PIL (version 1.1.7) twenty times with slightly different settings, the trick was for me to delete all libjpeg files in / usr / local / include (headers), as well as files under / user / local / lib.

I did not need to install PIL from the source, I used pip install pil

0
source

I am trying to install PIL (OS X 10.7.5, Python 2.7.3) for 5 hours. I, too, got stuck with the "Symbol not found: _jpeg_resync_to_restart" error and tried many of the proposed solutions to no avail, including reinstalling all of its dependencies. Finally, I discovered a double-click installation of Pillow .

Thank Rudix Now "import PIL" and "import _imaging" work!

ps I installed libjpeg through , I did not specifically remove this installation, so I'm not sure if this was part of the final solution or not.

0
source

All Articles