Installing PIL on Snow Leopard - python

Hey, i have a problem installing PIL on Snow.
I have a clean installation of macports after the upgrade to SL and installed from source the jpeg library following the OS specific installation instructions. Installing PIL with pip goes well but when i try to import the _imaging module i get the following message:
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PIL/_imaging.so, 2): no suitable image found. Did find:
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PIL/_imaging.so: mach-o, but wrong architecture

MacPorts already has a PIL port that will do all the work for you!
sudo port install py26-pil
You should first go into the site-packages directory and elsewhere to remove the stuff you installed manually, though. MacPorts will install all the necessary dependent libraries.

PIL on Mac OS X has been a pain point for many of my friends. These instructions seem to often help speedup the enlightenment process:
http://passingcuriosity.com/2009/installing-pil-on-mac-os-x-leopard/
Good luck!

I had the same problems, and actually created a small tutorial on how to resolve this.
getting a working copy of PIL, libjpeg and Imaging on Snow Leopard or even Lion
My default version of Python was still on 2.6 so I had to switch to 2.7
defaults write com.apple.versioner.python Version 2.7
get v8c of jpeg
cd into jpeg directory.
sudo make clean
CC="gcc -arch i386" ./configure --enable-shared --enable-static
make
sudo make install
get imaging i am using 1.1.6
untar
cd into imaging
sudo rm -rf build
vi setup.py
JPEG_ROOT = libinclude(“/usr/local/lib”)
sudo python setup.py install
And it’s that simple
Run your python interpreter,
import PIL
import _imaging
import Image
if all is well, then your all set.

I'm not entirely certain (I use a PC myself), but I think that you might find something interesting here
May the force be with you

Related

Cannot import sqlite3 in Python3

I am unable to import the sqlite3 module in Python, version 3.5.0. Here's what I get:
>>> import sqlite3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/sqlite3/__init__.py", line 23, in <module>
from sqlite3.dbapi2 import *
File "/usr/local/lib/python3.5/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: No module named '_sqlite3'
I know, I know, there are PLENTY of StackOverflow posts and support forums across the web where people complain about this problem, but none of the posted solutions have worked for me so far. Here's where I've been:
I also have Python 2.6.6 installed on this server, which is running CentOS 6.8 x86_64. I can open up the Python REPL and import sqlite3 just fine when using Python 2.6.6. I can also use sqlite3 from straight from bash and nothing seems awry.
This helpful question looked promising. I tried to re-configure and re-compile Python3.5 with the --enable-loadable-sqlite-extensions option, as user jammyWolf suggested. Nope, same error still occurs.
I've been using virtual environments like a good boy, but I have root access to this server. So, I was a bad boy and ran python3 as root without any virtualenvs activated. Still no luck. So I don't think it has anything to do with permissions.
I noticed that in the error message, it says No module named '_sqlite3'. This thread suggests that the underscore before the module name means that the module is an implementation detail, and isn't exposed in the API. ... I'm not sure what to make of this information, but there may be a hint somewhere in there.
Any ideas?
Falsetru is correct, I am going to go into a bit more detail for those not familiar (linux instructions). If you are getting this error, chances are you are using a version of python that was compiled without the correct headers. Here's a step by step guide to get it sorted. (Python 3.X.X instructions)
Install the required sqlite libraries
sudo apt-get install libsqlite3-dev
Uninstall python (I'm using python 3.6.5 as an example in this guide)
sudo apt-get remove python3.6
Download python from source
cd /tmp && wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
Unpack the archive
tar -xvf Python-3.6.5.tgz
Configure
cd Python-3.6.5 && ./configure
Make and install (and go make coffee while you're at it)
make && sudo make install
If you did everything correctly running "python3.6 -V" should give you your python version. Note you will have to rebuild any virtual environments you have as well.
One final caveat you may encounter.
zipimport.ZipImportError: can't decompress data; zlib not available
This happens if you don't have the following zlib library installed:
sudo apt-get install zlib1g-dev
Install sqlite-devel package which includes header, library that is required to build sqlite3 extension.
yum install sqlite-devel
NOTE: Python does not include sqlite3 library itself, but an extension module (wrapper).
I copied sqlite3.dll to this folder:
C:\Users\*****\Anaconda3\DLLs
It worked after two weeks trying everything else.

While upgrading python imaging library (PIL), it tells me "JPEG support not available"

Using ubuntu 13.10, python 2.7.5:
>>> import _imaging, Image
>>> from PIL import Image, ImageDraw, ImageFilter, ImageFont
>>> im = Image.new('RGB', (300,300), 'white')
>>> draw = ImageDraw.Draw(im)
>>> font = ImageFont.truetype('arial.ttf', 14)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/PIL/ImageFont.py", line 218, in truetype
return FreeTypeFont(filename, size, index, encoding)
File "/usr/local/lib/python2.7/dist-packages/PIL/ImageFont.py", line 134, in __init__
self.font = core.getfont(file, size, index, encoding)
File "/usr/local/lib/python2.7/dist-packages/PIL/ImageFont.py", line 34, in __getattr__
raise ImportError("The _imagingft C module is not installed")
**ImportError: The _imagingft C module is not installed**
>>>
So why does this happen? And how can I fix it? I followed the following instructions which I found at the bottom of this thread:
pip uninstall PIL
apt-get install libjpeg-dev
apt-get install libfreetype6-dev
apt-get install zlib1g-dev
apt-get install libpng12-dev
pip install PIL --upgrade
But while upgrading PIL, look what I saw:
--------------------------------------------------------------------
PIL 1.1.7 SETUP SUMMARY
--------------------------------------------------------------------
version 1.1.7
platform linux2 2.7.5+ (default, Sep 19 2013, 13:48:49)
[GCC 4.8.1]
--------------------------------------------------------------------
*** TKINTER support not available
*** JPEG support not available
*** ZLIB (PNG/ZIP) support not available
*** FREETYPE2 support not available
*** LITTLECMS support not available
--------------------------------------------------------------------
Is it normal for support for all these items not to be available? how do I fix that?
PIL is essentially dead, the fork Pillow is really what you should be using. You need to import it via
from PIL import Image, ...
It maintains all of the functionality of PIL, and adds a lot more, including Python 3 compatibility. Additionally, it's under active development, unlike PIL, so any bugs you find actually have a chance of getting fixed - same with feature requests.
You can install it (after uninstalling PIL) by running
pip install Pillow
I believe there's a package for Ubuntu, but my VM is giving me headaches at the moment and I can't check...
According to this question at AskUbuntu:
It turns out that the APT installations put the libraries under /usr/lib/x86_64-linux-gnu and PIL will search for them in /usr/lib/. So you have to create symlinks for PIL to see them.
In other words, PIL apparently doesn't understand modern Ubuntu, or in fact most 64-bit linuxes.
What you probably want to do is:
Switch to Pillow as MattDMo suggests,
Use an Ubuntu package for PIL (python-imaging) instead of trying to install via pip, or
Do both—use an Ubuntu package for Pillow, if there is one.
Checking on packages.ubuntu.com, the python-imaging package is in fact Pillow 2.0.0 on Saucy (13.10). In fact, it's Pillow on anything Raring or later; it's only people still using 12.x or earlier versions who are stuck with PIL. So, if you just do this:
$ sudo pip uninstall PIL
$ sudo apt-get install python-imaging
… that will get you Pillow, and pull in any dependencies it needs, all in one step.
If you don't want to do any of those, you should first reconsider that decision because it's probably a mistake, and then look at the workarounds suggested on that answer. In particular, symlinking the libs you installed into your /usr/lib directory is probably what you need. So, for example:
$ sudo pip uninstall PIL
$ sudo apt-get install libjpeg-dev
$ sudo ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib/libjpeg.so
$ # repeat for the various other libraries, but JPEG is the one you asked about
$ sudo pip install PIL
Alternatively, you could patch PIL itself, as some of the answers on the linked question show. In particular, add these two lines:
add_directory(library_dirs, "/usr/lib/x86_64-linux-gnu")
add_directory(library_dirs, "/lib/x86_64-linux-gnu")
… after the lines that add /usr/local/lib and /usr/lib.
However, if you're going to use a patched PIL, why not use Pillow, which has already solved this problem and many others?
Additional notes for Mac OS X
On Mac OS X you will usually install additional software such as
libjpeg or freetype with the "fink" tool, and then it ends up in
"/sw". If you have installed the libraries elsewhere, you may have
to tweak the "setup.py" file before building.
Additional notes for Windows
On Windows, you need to tweak the ROOT settings in the "setup.py"
file, to make it find the external libraries. See comments in the
file for details.
Make sure to build PIL and the external libraries with the same
runtime linking options as was used for the Python interpreter
(usually /MD, under Visual Studio).
Note that most Python distributions for Windows include libraries
compiled for Microsoft Visual Studio. You can get the free Express
edition of Visual Studio from:
http://www.microsoft.com/Express/
To build extensions using other tool chains, see the "Using
non-Microsoft compilers on Windows" section in the distutils handbook:
http://www.python.org/doc/current/inst/non-ms-compilers.html
For additional information on how to build extensions using the
popular MinGW compiler, see:
http://mingw.org (compiler)
http://sebsauvage.net/python/mingw.html (build instructions)
http://sourceforge.net/projects/gnuwin32 (prebuilt libraries)

Error installing Python Image Library using pip on Mac OS X 10.9

I want to install PIL on Mavericks using pip but get this error.
_imagingft.c:73:10: fatal error: 'freetype/fterrors.h' file not found
#include <freetype/fterrors.h>
^
1 error generated.
error: command 'cc' failed with exit status 1
My Command Line Tools are installed and up to date and every hint I found didn't help.
How can I get this to compile?
EDIT: I just checked, freetype is also already installed via homebrew
Instead of symlinking to a specific version of freetype2, do this:
ln -s /usr/local/include/freetype2 /usr/local/include/freetype
This saves you the trouble of recreating the symlink whenever you upgrade freetype2.
With macports, the solution that worked for me:
sudo port install freetype
sudo ln -s /opt/local/include/freetype2 /opt/local/include/freetype
And then re-run the PIL build process.
I've solved this problem with this symlink:
ln -s /usr/local/Cellar/freetype/2.5.1/include/freetype2 /usr/local/include/freetype
I have freetype already installed via homebrew too.
This is caused by a change in the headers of freetype >= 2.1.5. PIL is not using the correct documented way to include the freetype headers, which causes the build to fail now that freetype finally removed the long-deprecated way of including the headers. This problem is documented right at the top of http://freetype.sourceforge.net/freetype2/docs/tutorial/step1.html:
NOTE: Starting with FreeType 2.1.6, the old header file inclusion scheme is no longer supported. This means that you now get an error if you do something like the following:
#include <freetype/freetype.h>
#include <freetype/ftglyph.h>
Please take this problem upstream to the developers of PIL and advise them to use the documented way of including freetype headers:
#include <ft2build.h>
#include FT_ERRORS_H
After many attempts, I solved this problem compiling the PIL without freetype support. To do that, I simply unlinked from my $PATH using brew unlink freetype and then, pip install PIL==1.1.7.
I just solved this using the steps described in this Stackoverflow answer.
Seems this is Xcode's fault for installing freetype in strange locations.
Use Pillow where this issue is fixed "for real":
https://github.com/python-pillow/Pillow/commit/c6040f618d8f2706a7b46d1cdf37d1a587f9701f
And where you can report issues and see them addressed in a timely fashion:
https://github.com/python-pillow/Pillow/issues
In my OSx, I found the .h file in /opt/local/include/freetype2 direcoty. So, I type
sudo ln -s /opt/local/include/freetype2/ /usr/local/include/freetype
it works
Maybe the best way is to add /opt/local/include to your clang's include path.
osx yosemite, this worked for me:
(virtualenv)
$ ln -s /opt/local/include/freetype2/ /usr/local/include/freetype2
$ pip install pil==1.1.7 --allow-external pil --allow-unverified pil
I'm using Arch Linux and had this issue. In my case had to manually download and unpack the zip file from https://pypi.python.org/pypi/Pillow/2.2.1#downloads . I then edited the file _imagingft.c to change the include path from freetype/fterrors.h to fterrors.h as there was no freetype subdirectory of /usr/include/freetype2 where fterrors.h was located. Finally python setup.py install worked fine.
Edit: I should mention this was the solution for installing Pillow, not PIL, but Pillow is just a fork of PIL and it may still be applicable to others with this issue.
If you're still looking for answers like I was after reading this and other googling, you may be interested to see this:
Warning
Pillow >= 2.1.0 no longer supports “import _imaging”. Please use “from PIL.Image import core as _imaging” instead.
from here
By the time you read this, the page will probably have changed, but the text will be still here at least.

Cannot install python packages from source-code

I need to install PIL (python imaging library) on my Ubunto10.4-32bit (EDIT:64bit) machine on my python2.5.4-32bit.
This question is also relevant to any other source package I guess (among those that I need are RPyC,psyco and numpy).
I downloaded the source-code since I can't find any neat package to do the job and did
a sudo python2.5 setup.py install.
output:
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Traceback (most recent call last):
File "setup.py", line 9, in <module>
import glob, os, re, struct, string, sys
File "/usr/lib/python2.5/struct.py", line 30, in <module>
from _struct import Struct, error
ImportError: No module named _struct
but
echo $PYTHONHOME
/usr
Well, in the file struct.py theres the line from _struct import Struct, error
This is part of the python source code itself so I really wonder whats wrong with the python installation, since the code fails to import the module.
I installed py2.5.4 by doing:
./configure --prefix=/usr
make altinstall
(using make altinstall since I need py26 as default python interpreter)
EDIT: This issue might have risen from mistakenly using a 64bit platform :) and 32bit python2.5 . So anyhow problem solved by reducing unnecessary complexities - switching to 32bit machine and porting app to python 2.6.
In short:
Try using the Ubuntu repository first. If the package isn't there, use easy_install. If all fails, download the package directly to your source folder.
Ubuntu repository (the apt-get approach)
Ubuntu (10.04 and newer) has most mainstream packages are available with apt-get. The naming convention is python-NAME, e.g. python-imaging or python-scipy.
This is the best way to go, since the native package manager will handle any dependencies and updates issues.
Run apt-cache search python | grep "^python-" | less to see a list of packages available for your system (I have over 1,200 in my 10.04 machine).
Setuptools
For packages that are not part of the Ubuntu repository, you can use the python easy-install tool. First, install the setup tool:
sudo apt-get install python-setuptools
And you can install any Python package, e.g. colorworld, using easy-install:
sudo easy_install colorworld
This gives you some degree of protection (e.g., handles dependencies) but updates are generally manual, and it's a real pain to reinstall all these packages in a new computer.
Manual download
You can always download the source code to some directory and add it to your PYTHONPATH. It's the best approach when you just need to evaluate a package or apply some quick-and-dirty solution.
sudo aptitude install python-imaging
This will install PIL library.
sudo aptitude install python-imaging
That will install PIL. But I'm not really sure how to help with your other packages. Maybe try searching for them in synaptic.

Problems with Snow Leopard, Django & PIL

I am having some trouble getting Django & PIL work properly since upgrading to Snow Leopard.
I have installed freetype, libjpeg and then PIL, which tells me:
--- TKINTER support ok
--- JPEG support ok
--- ZLIB (PNG/ZIP) support ok
--- FREETYPE2 support ok
but when I try to upload a jpeg through the django admin interface I get:
Upload a valid image. The file you
uploaded was either not an image or a
corrupted image.
It works fine with PNG files.
Any Ideas?
Cato
I had the same experience with Leopard 10.5.x
Here is what I did to fix it, (may not work for you).
Go to your PIL working folder (where you unzipped PIL)
cd to your build folder
cd to your lib.macosx-10.* folder (specific to your os)
remove *.so
cd back to your PIL build folder
(I logged in as su for this, but you can sudo these if you like)
python setup.py clean
python setup.py build
python setup.py install
This rebuilds PIL clean. The reason your jpeg reports ok, is that it just looks for the existence of the jpeg lib files, but not the dependency that happens from a clean build and install of PIL.
Hope this solves your problem, mine was more likely related to the order of installation but maybe it will help...
Ken
As a follow up to Ken's response, I had the same problem with Snow Leopard 10.6.x which was caused by installing PIL before libjpeg. After installing libjpeg, I reinstalled PIL by doing the following.
cd to PIL working folder
python setup.py clean
python setup.py build_ext -i <-- This rebuilds PIL
python selftest.py - Run the selftest to confirm PIL is installed ok
python setup.py install
I ran into a similar issue while on Ubuntu 8.04. I was able to get myself out of it by simply re-issuing my PIL install (via pip):
pip install PIL --upgrade
Not sure what the issue was but I suspect it's similar to what others here reported.

Categories