【问题标题】:Python Imaging Library errors with libjpeglibjpeg 的 Python 映像库错误
【发布时间】:2011-07-30 03:35:30
【问题描述】:

我有一个 centos 5,正在尝试启动 Python Imaging 库。我安装了 libjpeg、libjpeg-devel 等,但仍然无法将 jpeg 图像上传到我的 django 站点。

我已经多次重新安装 PIL。通过 PIP,通过 easy_install2.6 并手动构建。每次它显示 JPEG 支持可用 - 但不会让我上传 jpeg 文件。它会接受 gif 和 png。

我正在运行 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
--------------------------------------------------------------------

有什么想法吗?

谢谢

【问题讨论】:

  • 请更准确地说明您看到问题所采取的步骤以及您所看到的错误回溯。

标签: python django python-imaging-library libjpeg


【解决方案1】:

确保您没有安装正在使用的不同版本的 libjpeg。要检查它,请尝试

lsof | grep libjpeg

【讨论】:

    【解决方案2】:

    我遇到了同样的问题,并逐步记录了我的安装过程。很长:您可以在my blog 上找到它。

    它将帮助您解决以下问题:

    • 工作副本
    • 姜戈
    • PIL
    • 成像
    • libjpeg
    • mysql
    • 混帐
    • 阿帕奇
    • mod_wsgi
    • easy_install
    • django-imagekit
    • CentOS 5.4 上的 CDN 存储

    安装 Apache、MySQL、SQLite 和其他开发包

    ​​>
    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"
    

    本教程将假设您在生产环境中使用 MySQL,并且您也可以在开发环境中使用 SQLite。如果您正在使用另一个数据库,例如 PostgreSQL,那么您现在应该安装这些文件。另外,请注意,这些不是您的网络服务器所需的唯一软件包,这应该只是让您的 django 应用程序正常工作的最低要求。

    添加新用户

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

    在第 77 行附近显示“root ALL=(ALL) ALL add 用户名 ALL=(ALL) ALL

    从这里您可以更改为您的用户以保持根帐户不变。 如果您发现某些项目不想运行,您应该使用 sudo 命令

    在 Python 2.4 旁边安装 Python 2.6

    让 Python 2.6 在 CentOS 5.4 上运行而不破坏任何东西的诀窍是将它安装在默认的 Python 2.4 旁边。不要尝试更新默认的 Python 2.4,因为重要的 CentOS 模块需要 2.4。为此,您将配置 python 安装在 /opt/python2.6 中。在执行此步骤之前,请确保您已 yum 安装 sqlite-devel,因为当您编译 python 时,python 会查找 sqlite 头文件以便为其构建模块。

    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 ~
    

    在 /opt/Python2.6 中安装 Python 后,您需要创建指向它的符号链接。

    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/
    

    运行 ldconfig 以更新指向您的共享库的链接,然后检查您的 python 版本以确保您现在可以使用 2.6。另外,使用 yum 测试一下 Python 2.4 和 2.6 之间是否存在任何冲突。如果您确实遇到问题,请仔细检查您的符号链接并确保您没有与 /usr/bin/python 或 /usr/bin/python2.4 冲突。

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

    安装 setuptools、MySQL 扩展和 Django 1.1

    如果您之前安装了 setuptools,但您需要为 2.6 重新安装,以便将软件包安装在 /opt/python2.6 中。为了在 Django 中使用 MySQL,您需要下载、构建和安装它的扩展。

    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 ..
    

    设置和安装 mod_wsgi

    大多数 Django 社区使用 wsgi 作为与网络服务器交互的方式。我也更喜欢使用它,因为它快速且易于设置。本教程不会介绍如何设置您的应用程序以使用 wsgi(不过,我将在最后给出一个示例),但 django 项目有一个很好的教程。请注意,这一步非常重要。您可能以前使用 yum 安装了 mod_wsgi,但您需要下载并使用新的 2.6 构建它,以便它与您的应用程序一起使用。

    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 ..
    

    然后您需要编辑 Apache httpd.conf 以加载 mod_wsgi 模块。完成后重启 Apache。

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

    确保您的 Apache 在模块加载后重新启动

    /etc/init.d/httpd restart
    

    为您的虚拟主机创建一个单独的目录

    我喜欢将我所有的虚拟主机放在一个单独的目录中

    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>
    

    创建你的 mod_wsgi 文件

    根据我在网上进行的一些搜索,最好将您的 mod_wsgi 文件留在应用程序的父文件夹中。

    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()
    

    保存文件

    创建一个 .python-eggs 目录

    在我的网站上

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

    http://mikecantelon.com/story/installing_django_on_centos_5

    启动mysql服务器

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

    在 CENTOS 上安装 PIL

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

    安装 PIP 以使用 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
    

    安装 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
    

    用另一个用户配置 MySQL

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

    创建一个 Django 项目

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

    在您的项目中创建一个日志目录,因为 mod_wsgi 和 apache 需要此目录

    cd mysite
    mkdir logs
    

    符号链接您的管理媒体文件夹

    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/
    

    配置您的 /etc/httpd/conf/httpd.conf 文件以包含您的项目基本设置

    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>
    

    包括 VirtualHosts 配置文件

    Include conf/vhosts/*.conf
    

    将 WSGISocketPrefix 添加到 httpd.conf 文件的末尾

    WSGISocketPrefix /var/run/wsgi
    

    确保主机名与 Apache conf /etc/httpd/conf/httpd.conf 中的主机名相同 否则通过运行改变

    hostname "new_name"
    

    授予权限

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

    我发现这还不够好,所以我不得不关闭 SElinux

    vi /etc/selinux/config
    

    设置

    SELINUX=disabled
    

    根据博客删除您的 -Indexes http://www.thelinuxblog.com/apache-directory-index-forbidden-by-options-directive/

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

    配置防火墙

    sudo vi /etc/sysconfig/iptables-config
    

    确保以下变量设置为“是”: IPTABLES_SAVE_ON_STOP="是" IPTABLES_SAVE_ON_RESTART="是"

    打开网络端口:

    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
    

    重启iptables: sudo /sbin/service iptables 停止 sudo /sbin/service iptables 启动 确保规则仍然存在。请尝试重新启动服务器,以确保设置已启动。

    确保您的 MySQL 和 Apache 在重启后始终处于开启状态

    /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
    

    通过 easy_install 安装 South 以实现轻松的 db 迁移

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

    为 Rackspace/CDN 存储安装 Django-cumuls

    /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
    

    您现在应该可以访问您的服务器 IP 地址,并且应该会看到一个欢迎屏幕!

    从这里您可以开始开发您的应用程序,您应该能够启用您的管理员自动发现并设置 URL,以便您可以访问管理部分。

    【讨论】:

    • 如果可能,请在此处发布您的博客条目的简短摘要以供后人参考,这样即使您的网站将来出现故障,此答案也会有价值。
    • 谢谢 Chris,我会尽可能多地复制和粘贴。
    【解决方案3】:

    您的 models.py 文件中有什么?你的数据库中需要这样的东西。

    img = models.ImageField("Foo")
    

    Foo 是存储上传图片的地方。 确保在重新安装 PIL 之前安装了 libjpeg-devel,如果这不起作用,请运行

    easy_install pil | tee pil.log
    

    并在此处发布,以便我们进一步为您提供帮助。

    【讨论】:

      【解决方案4】:

      这对我有用 http://t.co/JfOC1iRi

      并在从 macport 安装所有先决条件后对 PIL 进行干净的重建,请务必运行以下命令:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-11
        • 1970-01-01
        • 1970-01-01
        • 2016-02-10
        相关资源
        最近更新 更多