加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

MacOS - 下升级python,安装PIL ,easy_install等

(2012-12-06 15:38:15)
标签:

mac

杂谈

分类: Mac/IOS那些事

[zz]在mac下升级python,安装PIL ,easy_install等

最近win7 折腾的差不多了。就又换到mac系统下玩。
随便把一些记录贴在这。
leopard默认带了python的环境是 2.5.1 的版本,主流版本是2.5.4(貌似)
so 就升级下python 到 2.5.4版本

安装python2.5.4
点击 http://www.python.org/ftp/python/2.5.4/Python-2.5.4.tgz (python.org子目录也被gfw和谐了,但是这样能下回来的)下载2.5.4的源码版进入解压缩后的目录运行
1)./configure
2)make
3)sudo make install
完成后,python将装在/usr/local中,
/usr/local/bin 中有python的相关可执行文件
python的库在 /usr/local/lib/python2.5 中
删掉/usr/bin中旧python的符号链接

cd /usr/bin/
sudo rm py*

建立新的符号链接指向刚刚安装的python2.5.4

sudo ln -s /usr/local/bin/python /usr/bin/python
sudo ln -s /usr/local/bin/pydoc /usr/bin/pydoc
sudo ln -s /usr/local/bin/pythonw /usr/bin/pythonw

然后 在终端 输入 python 看看,是不是可爱的

Python 2.5.4 (r254:67916, Dec 17 2009, 21:42:36)
[GCC 4.0.1 (Apple Inc. build 5484)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

出来了~

安装PIL (PIL是python的标准图形处理库)

http://effbot.org/downloads/ 下载pil  http://effbot.org/media/downloads/PIL-1.1.7.tar.gz
解压后
进入目录
sudo python setup.py build
python setup.py install

搞定

安装easy_install

mac os x 默认有一个easy_install工具,但它的package安装路径是指向原来的python2.5.1的。需要重新安装easy_install工具(setuptools)
下载 setuptools的源码 ,在你的个人目录中新建.pydistutils.cfg文件

vim ~/.pydistutils.cfg

官方说明文档 http://peak.telecommunity.com/DevCenter/EasyInstall#installation-instructions
添加如下内容

[install]
install_lib = /usr/local/lib/python2.5/site-packages
install_scripts = /usr/bin
mac 添加(依次新建 install_lib目录)

[install]
install_lib = ~/Library/Python/$py_version_short/site-packages
install_scripts = ~/bin
要不然会有如下错误--------------
error: can't create or remove files in install directory

The following error occurred while trying to add or remove files in the
installation directory:

    [Errno 2] No such file or directory: '/usr/local/lib/python/site-packages/test-easy-install-63407.pth'

The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

    /usr/local/lib/python/site-packages/

This directory does not currently exist.  Please create it and try again, or
choose a different installation directory (using the -d or --install-dir
option).
-----------------------------------------
进入setuptools的目录,运行
sudo python setup.py build
python setup.py install

第二种方法
setuptools的安装过程。同样是在http://pypi.python.org/pypi/setuptools这个地方下载setuptools-0.6c11-py2.7.egg文件到本地,使用chmod +x setuptools-0.6c11-py2.7.egg命令使文件成为可执行文件。然后运行sudo sh setuptools-0.6c11-py2.7.egg命令完成安装。  (注意python和setuptools的对应版本)

以后就可以用

sudo easy_install django 等安装各种 packages 了

出现的错误

无法import的原因(ImportError: No module named *****)

python中,每个py文件被称之为模块,每个具有__init__.py文件的目录被称为包。只要模块或者包所在的目录在sys.path中,就可以使用import 模块或import 包来使用。

 

如果想使用非当前模块中的代码,需要使用Import,这个大家都知道。

如果你要使用的模块(py文件)和当前模块在同一目录,只要import相应的文件名就好,比如在a.py中使用b.py:

import b

但是如果要import一个不同目录的文件(例如b.py)该怎么做呢?

首先需要使用sys.path.append方法将b.py所在目录加入到搜素目录中。然后进行import即可,例如

import sys

sys.path.append('c:\xxxx\b.py')

大多数情况,上面的代码工作的很好。但是如果你没有发现上面代码有什么问题的话,可要注意了,上面的代码有时会找不到模块或者包(ImportError: No module named xxxxxx),这是因为:

sys模块是使用c语言编写的,因此字符串支持 '\n', '\r', '\t'等来表示特殊字符。所以上面代码最好写成:

sys.path.append('c:\\xxx\\b.py')

或者sys.path.append('c:/xxxx/b.py')

这样可以避免因为错误的组成转义字符,而造成无效的搜索目录(sys.path)设置。


安装 zlib许指定安装 目录

 

# tar -xvzf zlib-1.2.5.tar.gz

# cd zlib-1.2.5.tar.gz

# CFLAGS=-fPIC ./configure --libdir=/usr/lib64 [切记不要错!]

# make

# make install

安装 libevetn

make: Nothing to be done for `all' 解决方法 

 

1.这句提示是说明你已经编译好了,而且没有对代码进行任何改动。

若想重新编译,可以先删除以前编译产生的目标文件:
make clean
然后再
make

2.出现这种情况解决方法:

a.make clean 清除安装时留下的文件
b.在运行一下ldconfig

安装 wget

 

 tar zxvf wget-1.13.4.tar.gz
# cd wget-1.13.4
wget-1.13.4 root# ./configure  --with-ssl=openssl
wget-1.13.4 root# make
wget-1.13.4 root# sudo make install

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有