Installing PIL on Snow Leopard -- NOTHING WORKS - python

I'm trying to install PIL on Snow Leopard, using Python 2.6.1, GCC 4.2.1, PIL 1.1.7, and have tried with both libjpeg6b and libjpeg7 -- nothing works. I've cleared out every trace of libjpeg/pil/zlib from fink, tried various compiler options, etc. and used http://jetfar.com/libjpeg-and-python-imaging-pil-on-snow-leopard/ and http:// www.brambraakman.com/blog/comments/installing_pil_in_snow_leopard_jpeg_resync_to_restart_error/ (not a link because StOv only lets me post one...)
4 bits of potentially useful information:
OTOOL does not show libjpeg as a dependency
otool -L /Library/Python/2.6/site-packages/PIL/_imaging.so
/Library/Python/2.6/site-packages/PIL/_imaging.so:
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)
I get these weird compiler messages
i686-apple-darwin10-gcc-4.2.1: -framework: linker input file unused because linking not done
i686-apple-darwin10-gcc-4.2.1: Tcl: linker input file unused because linking not done
i686-apple-darwin10-gcc-4.2.1: -framework: linker input file unused because linking not done
i686-apple-darwin10-gcc-4.2.1: Tk: linker input file unused because linking not done
gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch ppc -arch x86_64 -pipe -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -IlibImaging -I/sw/include/freetype2 -I/sw/include -I/opt/local/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include -I/usr/local/include -I/usr/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c Tk/tkImaging.c -o build/temp.macosx-10.6-universal-2.6/Tk/tkImaging.o -framework Tcl -framework Tk
In file included from /System/Library/Frameworks/Tk.framework/Headers/tk.h:78,
from Tk/tkImaging.c:51:
selftest.py fails because of _imagingmath (after I used the second link given above, before it too failed due to _imaging)
Themistocles:Imaging-1.1.7 me$ python selftest.py
Traceback (most recent call last):
File "selftest.py", line 11, in <module>
from PIL import ImageMath
File "./PIL/ImageMath.py", line 19, in <module>
import _imagingmath
ImportError: No module named _imagingmath
Anything but selftest.py fails because of _imaging
>>> import _imaging
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(/Library/Python/2.6/site-packages/PIL/_imaging.so, 2): Symbol not found: _jpeg_resync_to_restart
Referenced from: /Library/Python/2.6/site-packages/PIL/_imaging.so
Expected in: flat namespace
in /Library/Python/2.6/site-packages/PIL/_imaging.so
Please, please help! This is getting ridiculous. I'd even be happy to be able to compile PIL sans jpeg support at this point!

I recently wrote an article on how to get PIL, django, libjpeg to work nicely alongside Snow Leopard
http://appelfreelance.com/2010/06/libjpeg-pil-snow-leopard-python2-6-_jpeg_resync_to_restart/
I'll copy it in here for you too.
If you don’t have this download it first.
http://www.ijg.org/files/jpegsrc.v7.tar.gz
go into your shell environment and untar by running the following
tar -zxvf jpegsrc.v7.tar.gz
cd jpeg-7
then run
sudo make clean
sudo CC="gcc -arch i386”"./configure --enable-shared --enable-static
sudo make
sudo make install
Next get PIL and untar it
http://effbot.org/downloads/Imaging-1.1.6.tar.gz
tar -zxvf Imaging-1.1.6.tar.gz
cd Imaging-1.1.6
If you already have PIL I would recommend running
sudo rm -Rf build
to clean any existing builds, this has caused me loads of errors and gray hairs!
in your settings.py file run find JPEG_ROOT
amend it so it looks as follows
JPEG_ROOT = libinclude(“/usr/local”)
Next move onto the build
sudo python setup.py build
if libjpeg is successfully installed you should be able to run python selftest.py without any errors relating to “jpeg”
sudo python setup.py install
if all has worked successfully you should be able to enter your python interpreter by executing python in your command line and also do the following:
import PIL
import Image
import _imaging
without any errors.
Just to triple check I have a simple jpeg on my desktop.
image = Image.open(“/Users/MyName/Desktop/myimage.jpeg”)
image.save(“/Users/MyName/Desktop/test.jpeg”)
should work without errors

Download macport:
http://www.macports.org/install.php
Then use it for pil:
http://trac.macports.org/browser/trunk/dports/python/py-pil/Portfile
I also had a lot of trouble with this, but port managed.

I've always gotten several screens worth of gcc errors when trying to install PIL. At some point I got something working (perhaps via MacPorts), so now my solution is to copy it to the appropriate site-packages (e.g. inside a new virtualenv).
I just posted it here: http://blogmaker.com/PIL-1.1.6-for-MacOSX-10.5-Leopard.zip
Works for me; I have no idea whether it will work for anyone else! Feel free to contact me with suggestions. And, let me know if there's a better place I should post it. PIL is both very cool and a royal hassle; it would be nice to have a definitive place for support. There are other PIL-related issues that I never solved.

Related

cross compiling gdb for arm with python failed

I want to debug ARM application on devices like Android machine, i prefer to use gdb(ARM version) than gdb with gdbserver to debug, because there is a dashboard , a visual interface for GDB in Python.
It must cooperation with gdb(ARM version) on devices,so i need to cross compiling a ARM version of gdb with python, the command used shows below:
./configure --host=arm-linux-gnueabi --target=arm-linux-gnueabi --with-python=/usr/bin
But finally a error message appeared:
configure:8096: checking whether to use python
configure:8098: result: /usr/bin/
configure:8316: checking for python2.7
configure:8334: arm-linux-gnueabi-gcc -o conftest -g -O2 -I/usr/include/python2.7 -I/usr/include/python2.7 conftest.c -ldl -ltermcap -lm -lpthread -ldl -lutil -lm -lpython2.7 -Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions >&5
In file included from /usr/include/python2.7/Python.h:8:0,
from conftest.c:50:
/usr/include/python2.7/pyconfig.h:15:52: fatal error: arm-linux-gnueabi/python2.7/pyconfig.h: No such file or directory
compilation terminated.
Then I find the line 15 in /usr/include/python2.7/pyconfig.h, as below:
# elif defined(__ARM_EABI__) && !defined(__ARM_PCS_VFP)
#include <arm-linux-gnueabi/python2.7/pyconfig.h>
Here is the point, I only have x86_64-linux-gnu/python2.7/pyconfig.h in /usr/include, how can I get the arm-linux-gnueabi/python2.7/pyconfig.h? I already apt-get install python2.7-dev.
I ran into this problem when attempting to cross-compile a python wrapper module built with SWIG, but it looks to me like it will happen to anyone cross compiling python-linked C code on a Debian system.
Apparently the Debian python-dev packages are not set up with the header files to facilitate a cross compile, but it is possible to go get them manually. I'm not sure if this is a python bug or a Debian package bug, and I haven't researched if it applies to other distros.
pyconfig.h sets preprocessor defines to tell the python source code about platform-depended things like endianness and data type sizes, so the proper pyconfig.h is definitely needed to correctly compile python source. Fortunately, the pyconfig.h file should be the only file you need to grab separately, and it is available from the Debian python-dev package for your target platform.
you can download the package file for armeabi or any other architecture from https://packages.debian.org/jessie/libpython2.7-dev and extract the include directory yourself, or you can use the following commands to download the package and copy the proper files for armeabi to /usr/local/include
wget http://security.debian.org/debian-security/pool/updates/main/p/python2.7/libpython2.7-dev_2.7.9-2+deb8u2_armel.deb
dpkg -x libpython2.7-dev_2.7.9-2_armel.deb libpython2.7-dev_2.7.9-2_armel_extracted
sudo cp -r libpython2.7-dev_2.7.9-2_armel_extracted/usr/include/arm-linux-gnueabi/ /usr/local/include/
rm -r libpython2.7-dev_2.7.9-2_armel*
Note that on some cross compilers you will have to add -I /usr/local/include to the compiler options if it does not search this location by default, but to me this is better than modifying /usr/include and risking your changes being wiped out by the OS

Building graph-tool on OSX with Python 3.4

I tried to install graph-tool on Mac OSX 10.10 using homebrew. The brew build process works fine, but when I try to import graph-tool I get the error described in this question.
Another problem with homebrew is that I always builds graph-tool for python2.7 and it installs the packages in the Python 2.7 sit-packages folder. But I want to use it with Python 3.4. These are the reasons why I tried to build graph-tool from source.
The ./configure command automatically uses Python 2.7, too. So I passed it the desired Python version with ./configure PYTHON=python3.4
It then detects the correct version as well as the related paths but crash with the following error:
configure: error:
Could not link test program to Python. Maybe the
main Python library has been installed in some non-standard library
path. If so, pass it to configure, via the LDFLAGS environment
variable.
Example: ./configure LDFLAGS="-L/usr/non-standard-path/python/lib"
======================================================================
ERROR!
You probably have to install the development version of the
Python package for your distribution. The exact name of this package varies
among them.
======================================================================
The error occurs with and without PYTHON variable set.
From the output of ./configure I can see that everything works fine except for the last line, which says:
checking consistency of all components of python development
environment... no
Whats does the above line mean and how do I properly install graph-tool on my maschine?
The error message is explaining exactly what needs to be done. Since python was installed in a non-standard path, you need to pass the flag LDFLAGS="-L/usr/non-standard-path/python/lib" pointing to the directory where the python libraries are located. This is most likely "/usr/local/lib", if you are using homebrew.
I was getting this error when I was trying to install graph-tool using outdated an autoconf / automake / pkg-config combination (installed using yum in CentOS 5.10). Installing those packages from source fixed the problem... although I'm not sure how this related to my python installation....
It worked for me by passing the variable PYTHON_EXTRA_LDFLAGS="-Wl,-stack_size,1000000 -F/usr/local/Cellar/python3/3.6.3/Frameworks -framework CoreFoundation".
In your case, it would be the path to the homebrew installation of python3.4.
The way I found out is that in the config.log, the error message shows the following:
configure:19023: checking python extra libraries
configure:19030: result: -ldl -framework CoreFoundation
configure:19037: checking python extra linking flags
configure:19044: result: -Wl,-stack_size,1000000 -framework CoreFoundation Python.framework/Versions/3.6/Python
configure:19051: checking consistency of all components of python development environment
configure:19079: gcc -o conftest -g -O2 -DNDEBUG -I/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/include/python3.6m -F/usr/local/Cellar/python3/3.6.3/Frameworks/ -Wl,-stack_size,1000000 -framework CoreFoundation Python.framework/Versions/3.6/Python conftest.c -L/usr/local/opt/python3/Frameworks/Python.framework/Versions/3.6/lib -lpython3.6m -ldl -framework CoreFoundation -ldl -framework CoreFoundation >&5
clang: error: no such file or directory: 'Python.framework/Versions/3.6/Python'
The error seems to be path 'Python.framework/Versions/3.6/Python', that in a homebrew installation does not exist. I search for the same path in the config.log and I found this line:
PYTHON_EXTRA_LDFLAGS="-Wl,-stack_size,1000000 -framework CoreFoundation Python.framework/Versions/3.6/Python"
So, the solution for me was to pass this variable with the right path.

Can't for the life of me get rpy2 installed - gcc error

I've gotten so many different install/build errors in trying to setup rpy2 on my Ubuntu 14.04 server in a virtual environment that I've lost track. This is the last step I have in setting up my iPython server, but I've been stuck on the rpy2 install for several days now. I've tried many different things, some of which I'm sure are conflicting with each other and making my life harder (such as the dual R version installs), but I'm giving up trying to do this without outside help.
Various things I've done:
Installed python-dev and setuptools
Installed and updated pip
Installed and updated gcc
Build and install the newest version of R from source
Build and install the development version of R (r-devel) from source using Dirk Eddelbuetel's Docker file
[sudo] pip install rpy2 with stable R and development R
build rpy2 from source with stable R and development R (with --ignore-check-rversion option set)
easy_install rpy2
pip install and source install with and without R_HOME set to stable R (current default R is the unstable development verison)
If anyone has any idea what I can do to get this working, besides starting from scratch in a clean environment, then please let me know - it will be greatly appreciated. Thank you!!
The current error that I'm getting is as follows:
(.venv)zacp#contentvalue:~/rpy2-2.6.0$ python setup.py build_ext --ignore-check-rversion install
R Under development (unstable) (2015-06-16 r68524) -- "Unsuffered Consequences"
setup.py:196: UserWarning: R did not seem to have the minimum required version number
warnings.warn("R did not seem to have the minimum required version number")
/usr/local/lib/R/bin/R CMD config --ldflags
R was not built as a library
/usr/local/lib/R/bin/R CMD config --cppflags
R was not built as a library
setup.py:211: UserWarning: No include specified
warnings.warn('No include specified')
setup.py:222: UserWarning: No libraries as -l arguments to the compiler.
warnings.warn('No libraries as -l arguments to the compiler.')
Compilation parameters for rpy2's C components:
include_dirs = []
library_dirs = []
libraries = []
extra_link_args = []
running build_ext
R Under development (unstable) (2015-06-16 r68524) -- "Unsuffered Consequences"
setup.py:77: UserWarning: R did not seem to have the minimum required version number
warnings.warn("R did not seem to have the minimum required version number")
building 'rpy2.rinterface._rinterface' extension
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DR_INTERFACE_PTRS=1 -DHAVE_POSIX_SIGJMP=1 -DRIF_HAS_RSIGHAND=1 -DCSTACK_DEFNS=1 -DHAS_READLINE=1 -I./rpy/rinterface -I/usr/local/lib/python2.7.9/include/python2.7 -c ./rpy/rinterface/_rinterface.c -o build/temp.linux-x86_64-2.7/./rpy/rinterface/_rinterface.o
In file included from /usr/local/lib/python2.7.9/include/python2.7/Python.h:8:0,
from ./rpy/rinterface/_rinterface.c:55:
/usr/local/lib/python2.7.9/include/python2.7/pyconfig.h:1182:0: warning: "_POSIX_C_SOURCE" redefined [enabled by default]
#define _POSIX_C_SOURCE 200112L
^
In file included from /usr/include/signal.h:28:0,
from ./rpy/rinterface/_rinterface.c:51:
/usr/include/features.h:230:0: note: this is the location of the previous definition
# define _POSIX_C_SOURCE 200809L
^
In file included from ./rpy/rinterface/_rinterface.c:58:0:
./rpy/rinterface/_rinterface.h:8:15: fatal error: R.h: No such file or directory
#include <R.h>
^
compilation terminated.
error: command 'gcc' failed with exit status 1
I guess the version of R that I installed with apt-get was out-of-date. R 3.0 is "probably OK" according to the documentation, and I guess I misinterpreted the warnings.
Whoops!
According to pip - Unable to Install rpy2 on Ubuntu 14.04, missing R_ext/Rallocators.h: - Ask Ubuntu, you need something more recent than R version 3.0.2, and version 3.2 was recent enough. That seems to be true e.g. for rpy2 version 2.8.5.

Undefined symbol when importing Python Sybase module on OSX 10.6

I'm trying to get the python-sybase module working on OSX 10.6, but I've run into a bit of a snag.
When I do
import Sybase
I get
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "Sybase.py", line 15, in <module>
from sybasect import *
ImportError: dlopen(/Library/Python/2.6/site-packages/python_sybase-0.40pre2-py2.6-macosx-10.6-universal.egg/sybasect.so, 2): Symbol not found: _blk_alloc
Referenced from: /Library/Python/2.6/site-packages/python_sybase-0.40pre2-py2.6-macosx-10.6-universal.egg/sybasect.so
Expected in: flat namespace
in /Library/Python/2.6/site-packages/python_sybase-0.40pre2-py2.6-macosx-10.6-universal.egg/sybasect.so
I took a look at sybasect.so, and sure enough, _blk_alloc is undefined. The function is located in Sybase's sybblk.dylib, which is installed, and its containing directory is in LD_LIBRARY_PATH.
When I compiled python-sybase using python setup.py build, the gcc command appears to find all of the right libs correctly, but for some reason those libs don't appear to be linked after installing sybasect.so to the Python module dir.
The gcc command is
gcc-4.2 -Wl,-F. -bundle -undefined dynamic_lookup -arch i386 -arch ppc -arch x86_64 build/temp.macosx-10.6-universal-2.6/blk.o build/temp.macosx-10.6-universal-2.6/databuf.o build/temp.macosx-10.6-universal-2.6/cmd.o build/temp.macosx-10.6-universal-2.6/conn.o build/temp.macosx-10.6-universal-2.6/ctx.o build/temp.macosx-10.6-universal-2.6/datafmt.o build/temp.macosx-10.6-universal-2.6/iodesc.o build/temp.macosx-10.6-universal-2.6/locale.o build/temp.macosx-10.6-universal-2.6/msgs.o build/temp.macosx-10.6-universal-2.6/numeric.o build/temp.macosx-10.6-universal-2.6/money.o build/temp.macosx-10.6-universal-2.6/datetime.o build/temp.macosx-10.6-universal-2.6/date.o build/temp.macosx-10.6-universal-2.6/sybasect.o -L/Applications/Sybase/System/OCS-15_0/lib -lsybblk -lsybct -lsybcs -lsybtcl -lsybcomn -lsybintl -lsybunic -o build/lib.macosx-10.6-universal-2.6/sybasect.so
The -L/Applications/Sybase/System/OCS-15_0/lib location is correct, and that folder contains all of the right .dylib's.
When I run otool the output is:
$ otool -L build/lib.macosx-10.6-universal-2.6/sybasect.so
build/lib.macosx-10.6-universal-2.6/sybasect.so:
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.11)
I was expecting to see the Sybase libs in there.
I'm a little new to linking on Mac. How do I ensure that sybasect.so references the Sybase libs?
Fixed it.
The problem was that the various Sybase libraries I was linking to were 32-bit only, but I was running Python in 64 bit mode. The fix was just running python in 32-bit mode.
I used the command defaults write com.apple.versioner.python Prefer-32-Bit -bool yes since I don't have any particular need for 64 bit mode.

Python barcode library Error [duplicate]

I have this problem:
No module named _imagingft
I have installed PIL, but it still does not work. I use OSX.
I'm trying to install this module for Django Simple Captcha.
Installing Pillow over existing PIL solved the issue for me:
$ sudo easy_install PIL
$ sudo easy_install Pillow
The suggest of Cristopher works very well for me.
Details follow:
1. Uninstall existing Python Imaging Library
Download and extract the source version (from here
http://effbot.org/downloads/Imaging-1.1.6.tar.gz)
Install freetype2 library (you need freetype cause _imagingft
handles TrueType fonts for captcha)
Modify setup.py (in PIL extracted source folder)to match the
freetype2 library (e.g. on my VPS with Centos I've changed line 'FREETYPE_ROOT = None'
to 'FREETYPE_ROOT = "/usr/local/include"')
Build PIL (python setup.py build) and verify that Freetype2 support
is ok
Install PIL (python setup.py build)
After installing you could verify existence of library, opening
python console and typing 'import instructions for _imagingft
library'.
If you use ubuntu you can use following manual:
http://helloworld.infobart.com/compiling-pil-on-ubuntu-natty
Thanks to a combination of resources (credit at the end) I've put together the following script, which works for me but YMMV. (Please check it carefully before running. It may have bugs that'll eat your liver, shave your cat, and run your car on leaded fuel):
#!/bin/bash
pip-2.6 uninstall PIL
# Just in case there's a virtualenv someplace:
pip uninstall PIL
# And forcibly clean up PIL as well
rm -rf /Library/Python/2.6/site-packages/PIL*
if [ ! -d "/usr/X11/include/freetype2" ];then
echo "You need to have XCode installed with the freetype libraries"
exit 1
fi
# Ok we're good to install ...
# Freetype is installed by XCode, so let's link to that for PIL's
# setup.py to know where to find things
ln -s /usr/X11/include/freetype2 /usr/local/include/
ln -s /usr/X11/include/ft2build.h /usr/local/include/
ln -s /usr/X11/lib/libfreetype.6.dylib /usr/local/lib/
ln -s /usr/X11/lib/libfreetype.6.dylib /usr/local/lib/libfreetype.dylib
pip-2.6 install PIL
# OR
# pip-2.6 install http://effbot.org/downloads/Imaging-1.1.7.tar.gz
Credits:
http://groups.google.com/group/python-virtualenv/browse_thread/thread/d42f8fd2c52e88b7
The stuff above
Looks like your PIL install didn't support Freetype. You may be missing some Freetype libraries and so your PIL install skipped support for it.
Freetype is the technology for handling fonts.
I was struggling with this myself. The solution is to install Pillow instead of PIL.
Excerpts From https://pypi.python.org/pypi/Pillow/2.0.0:
Pillow is the "friendly" PIL fork by Alex Clark and Contributors. PIL
is the Python Imaging Library by Fredrik Lundh and Contributors.
PIL is not setuptools compatible. ... Also, PIL's current bi-yearly
(or greater) release schedule is too infrequent to accomodate the
large number and frequency of issues reported.
The binary distribution for Windows also includes _imagingft. You no longer need to build your own from sources.
Download the installer packages from: https://pypi.python.org/pypi/Pillow/2.0.0#downloads
Or simply install with pip install pillow
I ran into a similar problem and the following solution worked for me, hence, I figured I would post it. Hopefully, it will help someone else while they try out the numerous solutions.
Firstly, I think some of the solutions up here will also work and I did use some of the above solutions as a spring board for my own.
[My Setup]
I run in my development virtual environment.
Mac OS X 10.7
pip
Django 1.3.1
XCode 4.2.1
I found that freetype2 is already included with your Mac OS X installation in /usr/X11/include
I am not sure if it is installed with XCode or just comes by default but from what I read and understood there are some patent issues which expired in 2010 which is why Apple does not 'turn on' the font library by default.
I had already installed libjpeg prior to install PIL using HomeBrew.
$ brew install libjpeg
Initially, I installed PIL using pip, but later uninstalled it and instead chose to install Pillow
Believe me or not, that just worked for me.
$ pip install Pillow
It seems like Pillow does the hairy work for you of linking and including the source from /usr/X11/lib as is show below in the installation procedure output:
Running setup.py install for Pillow
--- using frameworks at /System/Library/Frameworks
building '_imaging' extension
llvm-gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -DHAVE_LIBJPEG -DHAVE_LIBZ -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -I/usr/x11/include/freetype2 -IlibImaging -I/opt/local/include -I/usr/x11/include -I/Users//.virtualenvs/canoe_django_env/include -I/usr/local/include -I/usr/include -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _imaging.c -o build/temp.macosx-10.7-intel-2.7/_imaging.o
I hope this helps as it worked for me.
Sincerely.
Solution without modifying PIL source code:
install freetype2-dev package
export FREETYPE_ROOT=$(pkg-config --variable=libdir freetype2) # you can change to {path-to-freetype-library} if pkg-config is not available
install latest PIL version (pip install https://bitbucket.org/effbot/pil-2009-raclette/get/6a64b3083e35.tar.bz2)
Related PIL issue.
Another possible solution, if you're using Homebrew:
brew install freetype
brew install Pillow

Categories