安装PIL与Mac OS X上的Django配合使用 [英] Installing PIL to use with Django on Mac OS X

查看:115
本文介绍了安装PIL与Mac OS X上的Django配合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Mac OS X 10.6上安装PIL(Python Imaging Library),真的很烦。有没有人安装,可以在这里张贴食谱?我已经尝试了很多他们在这个网站上发布了很多从谷歌,但总是在失去一些部分,并无法正常工作与PIL ...



提前感谢
Ignas

解决方案

编辑:最近这个答案已经被投票了,想修改它以反映我现在在做什么。



首先,我已经从MacPorts切换到 Homebrew 在Mac OS X上进行包管理。其次,我从使用我的包管理器切换到使用 pip virtualenvwrapper 来管理我的Python库。



为什么我切换:



起初,只需几个Django项目,使用MacPorts保持所有最新版本变得非常简单。使用 python_select 可以使用多个版本的Python也很容易。我没有意识到,我正在做一个相当可怕的工作,保持多个图书馆并肩工作。当我升级我的软件包时,很明显,有时我真的不希望项目的Django版本更改。经过几个Django 1.1项目(现在运行Django 1.3),开始展示了奇怪的行为(由于CSRF中间件更改导致的表单未能提交,Django库中的小差异,管理应用程序资产的变化等)变得很明显,我应该看更好的解决方案。



我现在做的是:



在Mac OS X我转移到使用pip和virtualenvwrapper。首先,我安装virtualenvwrapper:

  pip install virtualenvwrapper 

这将抓住virtualenv和virtualenvwrapper。然后,您需要将以下内容添加到您的 .bashrc .profile source 它或打开一个新的shell。

  export WORKON_HOME = $ HOME / .virtualenvs 
source / usr / local / bin / virtualenvwrapper.sh#其中Homebrew放置它
export VIRTUALENVWRAPPER_VIRTUALENV_ARGS =' - no-site-packages'#可选

第1行设置变量 workon 需要查找其文件。第2行指向主shell脚本(这里的路径是Homebrew放置文件的位置,如果使用另一个包管理器,则可能会有所不同)。第3行是可选的,但我真的很喜欢它:它确保mainsite-packages存储库中当前没有安装的库将泄漏到新创建的虚拟环境中。我发现这样做会使事情变得干净,并且随着事情的升级,导致更少的惊喜。



下一步是创建一个新的虚拟环境:

  mkvirtualenv testEnvironmentName 

在制作环境之后,您将被放置在其中。如果您保留 - no-site-packages 标志,您可以键入 pip freeze 来查看您的Python库石板现在是空白的。要从虚拟环境中退出,请使用 deactivate 命令。要再次进入您的virtualenv,请使用 workon testEnvironmentName 。请注意,您可以在环境名称上使用选项卡完成。另请注意,键入 workon 本身将为您提供可用环境的列表。从这里你可以通过 pip install 你想要的任何图书馆,包括PIL。



要了解更多关于virtualenvwrapper,我建议您查看文档



这是另一个伟大的资源,教给我很多关于使用virtualenvwrapper 或只是查看截屏






ORIGINAL:



你也可以使用 MacPorts 安装PIL。软件包名称为 py-pil 有关该软件包的更多信息。我非常喜欢MacPorts over pip,因为我发现它给了我更多的可配置性,当涉及到保存几个版本的python和几个库安装。



这里MacPorts的安装说明: http://www.macports.org/install.php



另请参见:在Mac上安装python模块最兼容的方式是什么?


I'm really annoyed by installation of PIL (Python Imaging Library) on Mac OS X 10.6. Does anyone have it installed and could post the recipe here? I've tried a lot of them posted here on this site and a lot from google, but always anding with missing some part and can't work normally with PIL...

Thanks in advance. Ignas

解决方案

EDIT: This answer has been getting voted up recently, and I want to modify it to reflect what I'm doing now.

Firstly, I've switched from MacPorts to Homebrew for package management on Mac OS X. Secondly, I've switched from using my package manager to using pip and virtualenvwrapper to manage my Python libraries.

Why I switched:

At first, with just a few Django projects, it was very easy to keep everything up to date using MacPorts. It was also fairly easy to have multiple versions of Python using python_select. What I didn't realize was that I was doing a pretty terrible job of keeping multiple libraries working side-by-side. It became obvious as I upgraded my packages that sometimes I really didn't want a project's Django version to change. After a couple of Django 1.1 projects (now running Django 1.3) started exhibiting weird behaviour (forms failing to submit because of CSRF middleware changes, small differences in Django libraries, admin app assets changing, and so on) it became clear that I should look into a better solution.

What I do now:

On Mac OS X I'm moved over to using pip and virtualenvwrapper. First off, I install virtualenvwrapper:

pip install virtualenvwrapper

This will grab virtualenv and virtualenvwrapper. You then need to add the following to your .bashrc or .profile and source it or open a new shell.

export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh # where Homebrew places it
export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--no-site-packages' # optional

Line 1 sets up the variable workon needs to find its files. Line 2 points to the main shell script (the path here is where Homebrew places the file, it might be different if you're using another package manager). Line 3 is optional, but I really like it: it makes sure that no currently installed libraries in the "main" site-packages repository will leak into your newly created virtual environment. I find this keeps things clean and leads to fewer surprises down the road as things are upgraded.

The next step is to create a new virtual environment:

mkvirtualenv testEnvironmentName

After making the environment, you'll be placed into it. If you kept the --no-site-packages flag, you can type pip freeze to see that your Python library slate is now blank. To escape from the virtual environment, use the deactivate command. To get into your virtualenv again, use workon testEnvironmentName. Note that you can use tab completion on the name of the environment. Also note that typing workon by itself will give you a list of available environments. From here you can pip install any libraries you want, including PIL.

To learn more about virtualenvwrapper, I recommend checking out the documentation.

Here's another great resource which taught me a lot about using virtualenvwrapper (or just view the screencast)


ORIGINAL:

You can also instal PIL using MacPorts. The package name is py-pil. Here's more information on the package. I'm pretty fond of MacPorts over pip, as I find it gives me a bit more configurability when it comes to keeping several versions of python and several libraries installed.

Here are the installation instructions for MacPorts: http://www.macports.org/install.php

See also: What is the most compatible way to install python modules on a Mac?

这篇关于安装PIL与Mac OS X上的Django配合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆