Django OS X Wrong JPEG library version: library is 80, caller expects 62 sorl.thumbnail

前端 未结 4 770
野趣味
野趣味 2021-02-06 17:48

Im using sorl.thumbnail for django locally on my mac and have been having trouble with PIL, but today i finally managed to get it installed - was some trouble with libjpeg.

相关标签:
4条回答
  • 2021-02-06 18:13

    For the benefit of the people from the future who are encountering this error and don't know why, I'd like to post my findings. I hope to give a general understanding of what's gone wrong since the exact commands to fix it may be different on your machine than on my OSX Lion install.

    First, since it's easy to get lost in the potential solutions, it's important to understand that the error message is correct when it says Wrong JPEG library version: library is 80, caller expects 62 or some other combination of 62, 70, and 80. These numbers correspond to the different incompatible versions of libjpeg. There are two moving pieces here, the dynamically loaded jpeg library, and the PIL (or Pillow) install. What the error message is saying is that your PIL install was compiled with headers from libjpeg version 6.2, but when it goes to load up the actual shared library, it's being linked to version 8.0.

    The fix is to download, build, and install the libjpeg version you want (any will do, though the later versions build easier on OSX Lion):

     wget http://www.ijg.org/files/jpegsrc.v8d.tar.gz
     tar xzf jpegsrc*
     cd jpeg-*
     ./configure
     make
     sudo make install
    

    This should drop 2 files of note in '/usr/local/'. Namely /usr/local/lib/libjpeg.8.dylib and /usr/local/include/jpeglib.h. Now we just have to get PIL (or Pillow) to use these two files at install time, and we're home free. I know there's a better way to do this, but the hack (as recommended by the PIL docs) is to edit the setup.py file of the PIL distribution before you install it. You may get away with just setting JPEG_ROOT = libinclude('/usr/local') near the top of setup.py, though further directory manipulation may be necessary elsewhere in the file.

    As you fiddle with the paths, you have to make sure PIL does a full rebuild before you test out whether it linked up to the right library or not. I used a command like rm -rf build && python setup.py install to make sure the library was always freshly linked to the current path I was testing.

    I'm sorry this is a rambling answer, but it was very disheartening to have tried every other copy & paste solution out there and have none of them work. Hopefully this answer keeps at least a few folks from wasting numerous hours in search of a simplistic solution.

    Good Luck!

    0 讨论(0)
  • 2021-02-06 18:24

    Like a previous answer, I had a slightly different problem than the OP, but I wanted to share my solution here to help someone in the future.

    The only thing that worked for me was forcing pip to build pillow from source after installing the dev version of the needed libraries (my code was editing a jpg and adding a label using a custom font). This was on a ARM based embedded device running Ubuntu Linux using Python 3.7.3

    apt-get install -y libjpeg-dev libfreetype6-dev
    pip3 install pillow --global-option="build_ext" --global-option="--enable-jpeg" --global-option="--enable-freetype" 
    
    0 讨论(0)
  • 2021-02-06 18:26

    If you have macports installed, you should do a:

    $ sudo port selfupdate
    $ sudo port install py27-pil
    

    It's easier than the easy_install method since macports install the right dependencies.

    0 讨论(0)
  • 2021-02-06 18:28

    I had a slightly different problem than the OP, but I wanted to share my solution here to help someone in the future.

    OS: OSX El Capitan I installed libjpeg-turbo from the precompiled binaries on their website. However, I did not know that I already had a different version of libjpeg installed on my mac. I was building my c file like this gcc myfile.c -o myfile.out -L /opt/libjpeg-turbo/lib -ljpeg. This got the library from the correct location, but the the linker was getting the included header file jpeglib.h from the pre-installed location. I changed my build command to this: gcc myfile.c -o myfile.out -I/opt/libjpeg-turbo/include/ -L /opt/libjpeg-turbo/lib -ljpeg and it worked. No more library is 80, caller expects 62!

    0 讨论(0)
提交回复
热议问题