python 相关安装和配置

永久链接: http://michaelzqm.iteye.com/blog/1841966

预览文章: python环境搭建 《python 相关安装和配置》 《python 相关安装和配置》

2013

04

04
博客分类:

 

一. window环境安装

1. 安装python 2.7.3 (win7 64)

下载python-2.7.3.amd64.msi

 

2. 安装easy_install

 

3. 安装其他功能包

如:easy_install MySQL-python

easy_install -U DBUtils

问题解决:

.没有gcc编译环境

unable to find vcvarsall.bat

解决方法:安装编译环境(一个老外的帖子)

1)  First ofall download MinGW. Youneed g++compiler and MingW make in setup.

2)  If youinstalled MinGW for example to “C:\MinGW” then add “C:\MinGW\bin”to your PATH in Windows.(安装路径加入环境变量)

3)  Now startyour Command Prompt and go the directory where you have your setup.py residing.

4)  Last andmost important step:

setup.py install build --compiler=mingw32

或者在setup.cfg中加入:
[build]
    compiler = mingw32

 

 

4. 已编译版本安装

MySQL-python-1.2.3.win-amd64-py2.7.exe

 

5. api文档地址 2.7

http://docs.python.org/2/py-modindex.html

 

二. linux环境

 1.  下载DBUtils1.1
 wget http://www.webwareforpython.org/downloads/DBUtils/DBUtils-1.1.tar.gz

 2. 解压
 tar -xvf DBUtils-1.1.tar.gz 

 3. 安装DBUtils1.1
 cd DBUtils-1.1
 python setup.py install

 4. 安装MySQL-python
 yum install MySQL-python

 

5. 安装pip

yum install python-pip

检查

which pip-python

 

 

三. 数据挖掘环境

安装activepython,自带了easy_install

easy_install numpy

easy_install networkx

easy_install twitter

easy_install nltk

easy_install BeautifulSoup

 

四. 安装pil

windows64位

下载Pillow-2.0.0.win-amd64-py2.7.exe

下载地址:http://www.lfd.uci.edu/~gohlke/pythonlibs/

导入

windows用:from PIL import Image

linux用:import Image

 

 

centos 64位

wget “http://effbot.org/downloads/Imaging-1.1.7.tar.gz”

tar xvfz Imaging-1.1.7.tar.gz

cd Imaging-1.1.7

python setup.py build_ext -i

如果出错:command ‘gcc’ failed with exit status 1,需要安装python一个插件

yum install python-devel

如果使用pil时出错:decoder jpeg not available,则安装jpeg库

yum install libjpeg-devel

下载FREETYPE2

wget “http://sourceforge.net/projects/freetype/files/freetype2/2.4.8/freetype-2.4.8.tar.gz”

tar zxvf freetype-2.4.8.tar.gz 

cd freetype-2.4.8

make

make install

安装png库

yum install zlib zlib-devel

重新安装

python setup.py build_ext -i

python setup.py install

 

使用:

import sys
sys.path.append(“/root/Imaging-1.1.7/PIL”)
import Image

 

五. 安装python magick

window安装

1. 下载imagemagick并安装

http://www.imagemagick.org/script/binary-releases.php#windows

2. 安装wand

easy_install Wand

3. 示例代码

#!/usr/bin/env python
from urllib2 import urlopen
from wand.image import Image

def dowloadImg(url):
    f = urlopen(url);
    return Image(file=f);

def resizeImg(img, width, height):
    print img.size
    img.resize(width, height)
    img.save(filename = ‘temp_%s_%s.%s’ % (img.width, img.height, img.format))

if __name__ == ‘__main__’:
    img = dowloadImg(‘http://xxx.com/xxx.png’)
    resizeImg(img,64,64)
    resizeImg(img,48,48)

 

 centos

1. 安装imagemagick

yum update

yum  install  ImageMagick-devel

2. 安装 Wand

pip-python install Wand

    原文作者:lhj588
    原文地址: http://www.cnblogs.com/lhj588/p/3358789.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞