开发者

Python Imaging Library errors with libjpeg

I have a centos 5 and am trying to get Python Imaging library up and going. I installed libjpeg, libjpeg-devel, etc and am still not able to upload jpeg images to my django site.

I have reinstalled PIL several times. Through PIP, through easy_install2.6 and building manually. Each time it shows JPEG support available - yet won't let me upload jpeg files. It will accept gif and png though.开发者_开发知识库

I'm running python2.6, PIL 1.1.7

--------------------------------------------------------------------
PIL 1.1.7 SETUP SUMMARY
--------------------------------------------------------------------
version       1.1.7
platform      linux2 2.6.7 (r267:88850, Jul 28 2011, 12:07:21)
              [GCC 4.1.2 20080704 (Red Hat 4.1.2-50)]
--------------------------------------------------------------------
*** TKINTER support not available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
--- FREETYPE2 support available
*** LITTLECMS support not available
--------------------------------------------------------------------

Any ideas?

Thanks


Make sure you don't have a different version libjpeg installed which is being used. To check it, try

lsof | grep libjpeg


I had the same issues and documented my installation step by step. It's quite a long one: you can find it on my blog.

It will help you with the following:

  • A working copy
  • Django
  • PIL
  • Imaging
  • libjpeg
  • mysql
  • git
  • apache
  • mod_wsgi
  • easy_install
  • pip
  • django-imagekit
  • cdn storage on CentOS 5.4

Install Apache, MySQL, SQLite, and other developer packages

yum install httpd-devel mysql mysql-server
yum install mysql-client mysql-devel
yum install apr-devel sqlite3 sqlite-devel
yum install libjpeg libpng gcc make autoconf
yum install libxslt gettext zlib-devel
yum groupinstall "GNOME Desktop Environment"
yum groupinstall "Development Tools"

This tutorial will assume that you are using MySQL on production and you may also use SQLite for development. If you are using another database like PostgreSQL then you should install those files now. Also, please note that these are not the only packages that you will need for your webserver, this should just be considered a minimum to get your django app working.

Add New User

groupadd webmaster
useradd -c "username"  -g webmaster -m -s /bin/bash username
passwd username
passw0rd
visudo

Near line 77 where it reads “root ALL=(ALL) ALL add username ALL=(ALL) ALL

From here you can change to your user to leave the root account as is. If you find that some of the item do not want to run you should use the sudo command

Install Python 2.6 along side of Python 2.4

The trick to getting Python 2.6 working on CentOS 5.4 without breaking anything is to install it along side of the default Python 2.4. Do not try to update your default Python 2.4 because important CentOS modules require 2.4. To do this you will configure python to be installed in /opt/python2.6. Before you do this step make sure that you have yum installed sqlite-devel because python will look for the sqlite header files in order to build the module for it when you compile python.

wget http://www.python.org/ftp/python/2.6.4/Python-2.6.4.tgz
tar -zxvf Python-2.6.4.tgz
cd Python-2.6.4
./configure --prefix=/opt/python2.6 --with-threads --enable-shared --with-zlib=/usr/include
make
make install
cd ~

After Python is installed in /opt/Python2.6 you need to create symbolic links to it.

ln -s /opt/python2.6/lib/libpython2.6.so /usr/lib
ln -s /opt/python2.6/lib/libpython2.6.so.1.0 /usr/lib
ln -s /opt/python2.6/bin/python /usr/local/bin/python
ln -s /opt/python2.6/bin/python /usr/bin/python2.6
ln -s /opt/python2.6/lib/python2.6.so /opt/python2.6/lib/python2.6/config/

Run the ldconfig to update the links to your shared libraries and then check your python version to make sure you can now use 2.6. Also, test to see if there are any conflicts between Python 2.4 and 2.6 using yum. If you do have problems then double check your symbolic links and make sure that you are not conflicting with /usr/bin/python or /usr/bin/python2.4.

/sbin/ldconfig -v
python -V
yum info httpd

Install setuptools, MySQL extension, and Django 1.1

If you previously installed setuptools but you will need to do again for 2.6 so that the packages are installed in /opt/python2.6. In order to use MySQL with Django you will need to download, build, and install the extension for it.

wget http://bit.ly/6E0DNN 
chmod u+x setuptools-0.6c11-py2.6.egg
./setuptools-0.6c11-py2.6.egg --prefix=/opt/python2.6

wget http://bit.ly/6j4uID
tar -zxvf MySQL-python-1.2.3c1.tar.gz
cd MySQL-python-1.2.3c1
python setup.py build
python setup.py install
cd ..

wget http://www.djangoproject.com/download/1.1.1/tarball/
tar -zxvf Django-1.1.1.tar.gz
cd Django-1.1.1
python setup.py build
python setup.py install
cd ..

Setup and Install mod_wsgi

A majority of the Django community uses wsgi as the way to interface with the webserver. I also prefer to use it because it’s fast and very easy to setup. This tutorial will not go into setting up your app to use wsgi (however, I will give an example at the end), but the django project has a good tutorial for this. Please note that this step is very important. You may have previously installed mod_wsgi using yum but you will need to download it and build it using your new 2.6 in order for it to work with your app.

wget http://modwsgi.googlecode.com/files/mod_wsgi-2.8.tar.gz 
tar -zxvf mod_wsgi-2.8.tar.gz
cd mod_wsgi-2.8
./configure --with-python=/usr/local/bin/python
make
make install
cd ..

Then you will need to edit your Apache httpd.conf in order to load the mod_wsgi module. After this has been completed restart Apache.

vi /etc/httpd/conf/httpd.conf
LoadModule wsgi_module  /usr/lib64/httpd/modules/mod_wsgi.so
line 787
AddHandler wsgi-script .wsgi

Make sure your Apache restarts once the module has been loaded

/etc/init.d/httpd restart

Create a separate directory for your virtual hosts

I like to house all my vhosts in a seperate directory

cd /etc/httpd/conf
mkdir vhosts
cd vhosts
vi mysite.com.conf

<VirtualHost 127.0.0.1>
    ServerName localhost

    ErrorLog /www/django_test1/mysite/logs/error_log
    CustomLog /www/django_test1/mysite/logs/access_log combined

    UseCanonicalName Off

    Alias /media/ "/www/django_test1/mysite/media/"
    <Directory "/www/django_test1/mysite/media">
        Order allow,deny
        Options Indexes
        Allow from all
        IndexOptions FancyIndexing
    </Directory>

    Alias /mediaadmin/ "/opt/python2.6/lib/python2.6/site-packages/django/contrib/admin/media/"
    <Directory "/opt/python2.6/lib/python2.6/site-packages/django/contrib/admin/media">
        Order allow,deny
        Options Indexes
        Allow from all
        IndexOptions FancyIndexing
    </Directory>

    WSGIScriptAlias / /www/django_test1/mysite.wsgi
    WSGIDaemonProcess mysite processes=7 threads=1 display-name=%{GROUP}
    WSGIProcessGroup mysite
    WSGIApplicationGroup %{GLOBAL}
</VirtualHost>

Create your mod_wsgi file

According to a few searches I have done online it is best practive to leave your mod_wsgi file in the parent folder of the app.

mkdir /www
cd /www
mkdir django_test1
cd django_test1
vi mysite.wsgi

#!/opt/python2.6/bin/python

import os, sys

sys.path.append('/www/django_test1/mysite')
sys.path.insert(0, '/www/django_test1')
sys.path.insert(0, '/www/django_test1/mysite')

os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
os.environ['PYTHON_EGG_CACHE'] = '/www/django_test1/mysite/.python-eggs'

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

Save the file

Create a .python-eggs directory

in mysite

mkdir .python-eggs
chmod -R 777 .python-eggs

http://mikecantelon.com/story/installing_django_on_centos_5

Start the mysql server

/etc/rc.d/init.d/mysqld start

Install PIL on CENTOS

http://athenageek.wordpress.com/2009/06/09/easy_install-pil-not-so-easy/

Install PIP in order to use Imaging

/opt/python2.6/bin/easy_install-2.6 pip

/opt/python2.6/bin/pip install http://effbot.org/downloads/Imaging-1.1.6.tar.gz

Install GIT

http://www.bitsandpix.com/entry/git-installing-git-on-centos-5/

rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm

yum install git

Configure MySQL with another user

mysql --user=root mysql
CREATE USER 'webdev'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'webdev'@'localhost'
IDENTIFIED BY 'password' WITH GRANT OPTION;

Create a Django project

/opt/python2.6/bin/django-admin.py startproject mysite

Create a logs directory in your project as this is needed for mod_wsgi and apache

cd mysite
mkdir logs

Symlink your admin media folder

mkdir media
chmod -R 777 media
mkdir mediaadmin

ln -s /opt/python2.6/lib/python2.6/site-packages/django/contrib/admin/media /www/django_test1/mysite/mediaadmin/

Configure your /etc/httpd/conf/httpd.conf file to include your projects base settings

ServerAdmin admin@appelvm01.centos
HostName appelvm01.centos

ServerName 127.0.0.1

DocumentRoot "/www/django_test1/mysite"

<Directory "/www/django_test1/mysite">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>

include VirtualHosts config files

Include conf/vhosts/*.conf

add WSGISocketPrefix to httpd.conf end of file

WSGISocketPrefix /var/run/wsgi

Make sure hostname is equal to the one in Apache conf /etc/httpd/conf/httpd.conf else change by running

hostname "new_name"

Give permissions

chcon -R -h -t httpd_sys_content_t /www/django_test1/mysite

I found this wasnt good enough so I had to turn off SElinux

vi /etc/selinux/config

set

SELINUX=disabled

According to a blog remove your -Indexes http://www.thelinuxblog.com/apache-directory-index-forbidden-by-options-directive/

vi /etc/httpd/conf.d/welcome.conf
# -Indexes
Indexes

Configure Firewall

sudo vi /etc/sysconfig/iptables-config

Make sure following variables are set to “yes”: IPTABLES_SAVE_ON_STOP="yes" IPTABLES_SAVE_ON_RESTART="yes"

Open Web ports:

sudo /sbin/iptables -I INPUT -p tcp -m state --state NEW,ESTABLISHED --dport 80 -j ACCEPT
sudo /sbin/iptables -I INPUT -p tcp -m state --state NEW,ESTABLISHED --dport 443 -j ACCEPT

Restart iptables with: sudo /sbin/service iptables stop sudo /sbin/service iptables start Make sure rules are still in. Try restarting server, too, to make sure setting picked up.

Make sure your MySQL and Apache are always on after restart

/sbin/chkconfig --add httpd
/sbin/chkconfig --level 2345 httpd on
/sbin/chkconfig --list httpd

/sbin/chkconfig --add mysqld
/sbin/chkconfig --level 2345 mysqld on
/sbin/chkconfig --list mysqld

Install South through easy_install to allow for easy db migration

/opt/python2.6/bin/easy_install-2.6 South

Install Django-cumuls for Rackspace/CDN storage

/opt/python2.6/bin/pip install django-cumulus

/opt/python2.6/bin/pip install -r http://bitbucket.org/richleland/django-cumulus/raw/0.3.3/requirements.txt

/opt/python2.6/bin/easy_install-2.6 django-imagekit

You should now be able to go to your servers ip address, and you should see a welcome screen!

From here on you can start developing your app, you should be able to enable your admins autodiscover and set the urls so that you can access the admin section.


what's in your models.py file? You'll need something like this in your database.

img = models.ImageField("Foo")

where Foo is the place to store uploaded images. make sure you've got libjpeg-devel installed before reinstalling PIL, and if that doesn't work, run

easy_install pil | tee pil.log

and post it here so we can help you further.


This worked for me http://t.co/JfOC1iRi

And to do a clean rebuild of PIL after installing all pre-requisites from macport, be sure to run the following:

 $ python setup.py clean
 $ python setup.py build_ext -i
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜