python 相關安裝和配置

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

預覽文章: python環境搭建 編輯 刪除

2013 - 04 - 04
博客分類:
 

一. window環境安裝php

1. 安裝python 2.7.3 (win7 64)html

下載python-2.7.3.amd64.msipython

 

2. 安裝easy_installlinux

 

3. 安裝其餘功能包web

如:easy_install MySQL-pythonwindows

easy_install -U DBUtilscentos

問題解決:api

.沒有gcc編譯環境bash

unable to find vcvarsall.batapp

解決方法:安裝編譯環境(一個老外的帖子)

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

相關文章
相關標籤/搜索