分享

python环境搭建

 心不留意外尘 2016-04-24

from http://michaelzqm./blog/1841966

2013.04

一. window环境安装

1. 安装python 2.7.3 (win7 64)

下载python-2.7.3.amd64.msi

 设置python环境变量:D:\bin\Python27

 

2. 安装easy_install

win7 64位系统:下载文件

http://peak./dist/ez_setup.py

python ez_setup.py

设置easy_install 环境变量 :D:\bin\Python27\Scripts;

 

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./2/py-modindex.html

 

6. python mongodb

easy_install -U pymongo

 

7. protobuf 安装

可以用SVN从服务器上(http://protobuf./svn/trunk)下载最新的protobuf。我使用的是protobuf-2.6.0。

进入protobuf-2.4.1/vsprojects利用VS2010进行编译。生成的protoc.exe放到protobuf-2.6.0/src下。如果不放,后面无法安装python版的protobuf。

编译python版本的protobuf

在protobuf-2.6.0\python下运行python setup.py build,然后再执行python setup.py install。

注意:如果第3步的protoc.exe没有放,会出现错误找不到google\protobuf\compiler目录。

 

 

8 . 安装python memcache

easy_install python-memcached

 

 

二. linux环境

 1.  下载DBUtils1.1
 wget http://www.webwarefor/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

可能需要yum install mysql-devel

 

5. 安装pip

yum install python-pip

检查

which pip-python

 

6. poster安装

pip install poster

 

7. protobuf

wget http://protobuf./files/protobuf-2.5.0.tar.gz
 tar xvf protobuf-2.5.0.tar.gz
 cd protobuf-2.5.0
 ./configure --prefix=/usr/local/protobuf
 make
 make check
 make install
 vim /etc/profile
 export PATH=$PATH:/usr/local/protobuf/bin/
 export PKG_CONFIG_PATH=/usr/local/protobuf/lib/pkgconfig/
 source /etc/profile
 
 cd python/
 python setup.py install
 python setup.py build
 python setup.py install

 

三. 数据挖掘环境

安装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./~gohlke/pythonlibs/

导入

windows用:from PIL import Image

linux用:import Image

 

 

centos 64位

wget "http:///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:///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./script/binary-releases.php#windows

MAGICK_HOME

C:\Program Files\ImageMagick-6.7.7-Q16

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.png')
    resizeImg(img,64,64)
    resizeImg(img,48,48)

 

 centos

1. 安装imagemagick

yum update

yum  install  ImageMagick-devel

2. 安装 Wand

pip-python install Wand

----------------------------------------------------------------------------某些环境安装有问题,先贴安全历史记录命令

convert -version
python
cat /etc/profile
ls /usr/local/lib/libImage*
ls /usr/local/lib/libMagick*
yum -y remove ImageMagick
pip

a) 安装pip
#wget  http:///distribute_setup.py
#python distribute_setup.py
#wget https://github.com/pypa/pip/raw/master/contrib/get-pip.py
#python get-pip.py

wget https://bootstrap./ez_setup.py

python ez_setup.py

https://pypi./pypi/pip

下载最新pip,解压

python setup.py install

vim /etc/profile

添加:

PATH=/usr/local/python27/bin:$PATH

export path

b)安装图库
wget http://www./download/delegates/libpng-1.6.6.tar.gz
#wget http://www./download/delegates/libpng-1.6.2.tar.gz
tar xzvf libpng-1.6.6.tar.gz

cd libpng-1.6.2
./configure --prefix=/usr/local
make
make install
cd ..
wget http://www./download/ImageMagick.tar.gz
tar xzvf ImageMagick.tar.gz
cd ImageMagick-6.8.7-8
export CPPFLAGS=-I/usr/local/include
export LDFLAGS=-L/usr/local/lib

./configure --prefix=/usr/local --disable-static --with-modules --without-perl --without-magick-plus-plus --with-quantum-depth=8 --with-gs-font-dir=/usr/local/share/ghostscript/fonts

#wget http://hivelocity.dl./project/freetype/freetype2/2.3.11/freetype-2.3.11.tar.gz

wget http://download.savannah./releases/freetype/freetype-old/freetype-2.3.9.tar.gz
tar xzvf freetype-2.3.11.tar.gz
cd freetype-2.3.11
./configure --prefix=/usr/local
make
make install

wget http://www./files/jpegsrc.v8.tar.gz
tar xzvf jpegsrc.v8.tar.gz
cd jpeg-8
#ln -s `which glibtool` ./libtool
./configure --enable-shared --prefix=/usr/local
make
make install

也可能需要高版本的如:

    tar -xzvf jpegsrc.v9.tar.gz 
    cd jpeg-9 
    ./configure 
    make libdir=/usr/lib64  
    make libdir=/usr/lib64 install 

wget ftp://ftp.remotesensing.org/pub/libtiff/tiff-3.9.2.tar.gz
tar xzvf tiff-3.9.2.tar.gz
cd tiff-3.9.2
./configure --prefix=/usr/local
make
make install


wget http:///releases/ghostscript-8.70.tar.gz
tar xzvf ghostscript-8.70.tar.gz
cd ghostscript-8.70/
./configure  --prefix=/usr/local
make
make install
cd ..
wget ftp://ftp./pub/ImageMagick/delegates/ghostscript-fonts-std-8.11.tar.gz
tar xzvf ghostscript-fonts-std-8.11.tar.gz
mv fonts /usr/local/share/ghostscript

 

c) 安装magick
cd ImageMagick-6.8.6-2/
./configure
make
make install

 

d) 配置文件

vim /etc/profile

添加如下内容

MAGICK_HOME=/usr/local
export MAGICK_HOME
export PATH=$PATH:/usr/local/bin:
source /etc/profile
echo 'source /etc/profile' >> ~/.bashrc
exit

 

e) 安装wand

 pip install wand

 

f) 测试

convert -version

 

 

六 django环境部署

wget --no-check-certificate "https://pypi./packages/source/D/Django/Django-1.6.tar.gz#md5=65db1bc313124c3754c89073942e38a8"

tar xvf Django-1.6.tar.gz

cd Django-1.6

python setup.py install

django-admin.py startproject projectname

python manage.py startapp appname

python manage.py runserver 0.0.0.0:8000

 

python manage.py syncdb

python manage.py makemigrations

python manage.py migrate

 

七 redis

1. 安装

pip install redis

 

2. 使用

import redis
r = redis.StrictRedis(host=’localhost’, port=6379, db=0)
r.set(‘foo’, ‘bar’)
r.get(‘foo’)

 

 六. mac环境搭建

1. 安装mac  python 

2. 安装pip,先下载https://raw./pypa/pip/master/contrib/get-pip.py

python get-pip.py

3.  安装MySQL-python

先下载源码

安装mysql-5.6.23-osx10.9-x86_64.dmg(不然会提示找不到mysql_config)

修改site.cfg :mysql_config = /usr/local/mysql/bin/mysql_config

然后(不设置会提示image not find):

 

sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib 

 

sudo ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql

最后:python setup.py install

 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多