install pil on virtualenv with libjpeg - django

Currently I'm installing PIL into my virtual env as follows:
pip install -E . -r ./releases/%s/requirements.txt
where requirements.txt contains:
pil
I can upload png images but not jpeg images currently. From reading on the web it seems i may need libjpeg decoder? Am i installing pil incorrectly? What is the proper way to install pil for django in a virtual env with libjpeg?

You should install the libraries that others recommended but most importantly you should tell PIL where to find them. Edit the setup.py so that
JPEG_ROOT = None
becomes
JPEG_ROOT = libinclude("/usr/lib")
I found that the easiest way was to download the source with pip but not install:
pip install --no-install PIL
edit the setup (inside the build directory of the virtual environment) and the install
pip install PIL
you can find some more information in my blog
You can also try pillow which seems to do great job with little hassle (pip install pillow)

On Ubuntu precise, PIL doesn't find the jpeg library files, even once they are installed. The easiest way to fix this is to make a symlink after you have installed the jpeg dev package.
So, I needed an extra step:
pip uninstall PIL
sudo apt-get install libjpeg8-dev
sudo ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib
pip install PIL

For Ubuntu 11.04, what finally worked for me is:
pip uninstall PIL
sudo apt-get install libjpeg8-dev
pip install PIL
The Python Imaging Library (PIL) seems really picky about version and location of the jpeg libraries. And because PIL is written in C and compiled, you need the development versions of the library in addition to the runtime versions.
The situation is so bad the community forked PIL to create a softer version: Pillow:
http://pypi.python.org/pypi/Pillow#why-a-fork

On OSX, I used the following binary to get libpng and libjpeg simultaneously installed systemwide:
libpng & libjpeg for OSX
Because I already had PIL installed (via pip on a virtualenv), I ran:
pip uninstall PIL
pip install PIL --upgrade
This resolved the decoder JPEG not available error for me.

You must install the libraries:
sudo aptitude install libjpeg62 libjpeg62-dev zlib1g-dev

if pip raises an error, try
easy_install PIL

Related

Django: determine actually used pip packages

I got a Django project that was started without virtualenv. Now migrating to virtualenv and my requirements.txt created before is huge and not installable in the virtualenv (many errors as shown below). How can i generate a minimal list of required packages? Or is there some reference anywhere?
Could not find any downloads that satisfy the requirement PIL==1.1.7 (from -r requirements.txt (line 8))
Some externally hosted files were ignored (use --allow-external PIL to allow).
Cleaning up...
No distributions at all found for PIL==1.1.7 (from -r requirements.txt (line 8))
it's not only PIL that throws errors, if I comment it another package shows and i can't know what's really used for my application to work.
Thanks in advance!
You can run pip freeze (related to system python used before virtualenv), this give you list of installed packages;
Then filter that list using following:
1) INSTALLED_APPS in settings
2) also check all from and import statement (search through the project)
I've had the same problem and there are issues getting PIL to install using PIP as there's no PIL 1.7 in the default Python repos.
The easiest fix is this to add these options to the pip:
--allow-external PIL --allow-unverified PIL
For example:
pip install -r requirements.txt --allow-external PIL --allow-unverified PIL
The problem with this it is a potential security issue and you don't want to do this on a production server! :)
Your options are to use Pillow which is a fork of PIL:
https://pypi.python.org/pypi/Pillow
Comments from the Pillow author, and you should verify that it works with you code.
Or try PIL 1.1.6 which is the Python Repos:
https://pypi.python.org/pypi/PIL
Or create your own repo and include the PIL 1.1.7 sources.
Or, if your on a Linux system install PIL using your distro's package management tool and remove PIL from your requirements file, and then rebuild your virutalenv.
You can this on Debian based distros like this:
sudo apt-get install python-imaging
Red Hat distros like this:
sudo yum install python-imaging

IOError decoder zip not available

I'm trying to get up and running with sorl thumbnail but I'm getting an error "decoder zip not available".
I have read through a ton of similar pages saying that it is a PIL / Pilow issue.
I have tried re-installing pil via:
easy_install http://dist.plone.org/thirdparty/PIL-1.1.7.tar.gz
As well as:
pip uninstall PIL Pillow
pip install Pillow
pip install PIL
I read that Ubuntu uses a directory called /lib/x86_64-linux-gnu for x64 architectures. If you are using that architecture you need to create a symbolic link for that as well as for other shared libraries.
$ sudo ln -s /lib/x86_64-linux-gnu/libz.so.1 /lib/libz.so
Additional info:
OS: Ubuntu Precice
I have not tried installing the package zlib from source which some others have also mentioned worked for them.
I found two solutions for this that worked for me.
The first way that worked for me was to use a different imaging library all together. I installed pgmagic and that worked fine.
sudo apt-get install libgraphicsmagick++-dev
sudo apt-get install libboost-python1.40-dev
There is also other imaging libraries available and they are all listed in the sorl-thumbnail docs:
http://sorl-thumbnail.readthedocs.org/en/latest/requirements.html
The second way that worked for me (preferred) was literally a fresh install of everything where I removed both pillow and PIL and the re-installed them starting with pillow.
pip uninstall pillow
pip uninstall PIL
pip install pillow
pip install PIL

How may i install the Python Imaging Library to django environment?

I am currently finding it hard to install PIL on precise pangolin.
I have followed this tutorial (http://www.sandersnewmedia.com/why/2012/04/16/installing-pil-virtualenv-ubuntu-1204-precise-pangolin/)
When I do:
pip install PIL
I get the error:
Could not find any downloads that satisfy the requirement PIL
No distributions at all found for PIL
Looked around google but to no avail.
Try this:
pip install PIL --allow-external PIL --allow-unverified PIL
You can use Pillow
--> pip install Pillow

decoder zip not available (Windows 7)

I installed django-photologue. But then when I try to save a photo in django admin it throws this error:
'decoder zip not available'
I have already un-installed and re-installed PIL. I hope someone can help me with the complete steps on how to overcome this error.
On Windows install PIL using the binary installer from the PIL website instead of using pip.
I was able to solve this cleanly on Windows with pip install --use-wheel Pillow. I'm not sure what changed because the PILLOW installs used to work on my windows setup. I must have some mixed versions or the default behaviors have changed.
Try the following instructions:
sudo pip uninstall PIL
sudo apt-get install libjpeg8 libjpeg62-dev libfreetype6 libfreetype6-dev
sudo ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib
sudo ln -s /usr/lib/x86_64-linux-gnu/libfreetype.so /usr/lib
sudo ln -s /usr/lib/x86_64-linux-gnu/libz.so /usr/lib
sudo pip install -U PIL
That should solve PIL problem decoder zip not available.

How can I tell whether/where python a virtualenv has been set up? (aka installing lxml on bitnami's djangostack)

I'm working on a django application on the bitnami djangostack. I want to use the lxml library, but I haven't been able to install it. Or rather, I haven't been able to install it where django can find it.
I've already used apt-get to install the libxml2, libxslt, and python-dev dependencies. Both of these commands report success*:
sudo pip install lxml
sudo apt-get install python-lxml
easy_install fails with a super-long error message that makes me think it can't find the dependencies. (I've run into this problem before.)
When I open up python or call python manage.py shell and try "import lxml", I get
"ImportError: No module named lxml"
As best I can tell, bitnami has set up a virtual environment for django, and pip and aptitude are installing lxml perfectly -- to the wrong python. Assuming that's all correct, how do I get lxml installed to the right one?
When you use apt-get install you are installing system libraries. BitNami DjangoStack is self-contained and independent. You could upgrade or remove your system libraries with apt-get and it would not be affected. Unfortunately lxml is not included in the stack nor libxslt which is a depency. We will include it in a future version however please find below the steps for manualing installing lxml on top of the python version included in BitNami DjangoStack.
You will need to use the system libraries for libxslt and libxml2. Be sure that you have them installed:
sudo apt-get install libxml2 libxml2-dev libxslt1.1 libxslt1-dev
Download lxml and uncompress it:
wget http://lxml.de/files/lxml-2.3.2.tgz
tar zxvf lxml-2.3.2.tgz
cd lxml-2.3.3
Load the BitNami environment:
. path_to_your_djangostack_installation/scripts/setenv.sh <-- notice the space between the dot and the path to the script.
which python <-- the output should be the python version from BitNami.
Install lxml specifying the path to your system libraries (notice that you should execute this command in the lxml directory):
python setup.py install --with-xslt-config=/usr/bin/xslt-config --with-xml2-config=/usr/bin/xml2-config
Now executing import lxml in the python console should work.
(This was already replied here)
There have been a couple of blog postings on installing this library on shared hosting. http://rhodesmill.org/brandon/2009/installing-lxml-on-webfaction/
How to install lxml for python without administative rights on linux?