python distribution 是什么意思

Python016

python distribution 是什么意思,第1张

python distribution

Python发行版

双语例句

1

The base Python distribution has a huge library of available routines and functions just waiting to be used.

基本的Python发行版提供许多库,其中包含马上可以使用的例程和函数。

2

Installation of ZSI is fairly painless as it uses standard python distutils for its distribution.

ZSI的安装相当轻松,因为它用标准的python distutils作为其分发版。

首先建议你安装一个扩展库安装工具,推荐easy_install工具,你可以在网上下载,也可以先去下载一个 ez_setup.py ,这个程序下载后用python.exe运行一下,会自动根据你的版本帮你下载和安装一个easy_install,目前只支持到python2.6,看来python3目前还是没有太多的公司在使用啊。。。

后面就可以用这个easy_install工具进行第三方库的下载了,比如我要下载soaplib这个库,可以执行easy_install soaplib,它会自己去相关网站查找这个库,以及这个库的依赖,如果你手工安装,那依赖会把你搞疯掉的

关于哪个库更适用做webservice

现在网上查到最多的是ZSI或者叫soappy,实际上05年之后就没有更新了,而且只支持到2.5,放弃

soaplib,这个目前2.0,还是不错的,不过手册不是太好读,只有server端的用法,client我没找到suds,这个我在用,用起来比较简单,示例代码如下:

[python] view plain copy

The library is now ready to use. We start by importing the suds library, creating a client based on a SOAP url, and asking the library to print the SOAP web service methods that are available to us.

import suds

url = "http://www.ecubicle.net/iptocountry.asmx?wsdl"

client = suds.client.Client(url)

print client

From the output of the last print command, we learn that there is a method called FindCountryAsString that takes one argument: the IP address.

print client.service.FindCountryAsString("194.145.200.104")

And it shows (edited for readability):

<?xml version="1.0"?>

<IPAddressService>

<country>Netherlands</country>

</IPAddressService>

Normally you want to have the contents of the SOAP body. This is what suds provides in a very elegant way. However, you’re a bit stuck when you want to get something from the SOAP header. The author of suds realised this and made a backdoor to get the information anyway. We start by showing what the function last_received contains:

print client.last_received()

<?xml version="1.0" encoding="UTF-8"?>

<soap:Envelope>

<soap:Header>

<ResponseHeader xmlns="">

<resultCode>1000</resultCode>

<resultDescription>Success</resultDescription>

</ResponseHeader>

</soap:Header>

<soap:Body>

...

</soap:Body>

</soap:Envelope>

We can get portions of this data by doing some XML handling. Let’s say we want to print the resultCode:

print client.last_received().getChild("soap:Envelope").getChild("soap:Header")

.getChild("ResponseHeader").getChild("resultCode").getText()

1. 更新系统组件

sudo apt-get update

sudo apt-get dist-upgrade

2.增加OpenERP用户

(如果之前用apt-get 或者deb方式安装过,先删除这个用户重新再创建下 sudo userdel openerp)

(一样的,如果有 /opt/openerp 这个目录 也先删除掉sudo rm -r /opt/openerp)

sudo adduser --system --home=/opt/openerp --group openerp

openerp用户被加入system组,该用户不能够从终端登录。

需要openerp用户操作时,可以用下面的命令切换 sudo su - openerp -s /bin/bash

完成相关操作后可以用exit退出openerp用户shell

3.安装并配置数据库

进入postgres用户shell(postgres是数据库默认的管理员,由安装程序创建)

sudo su - postgres

为OE创建数据库用户,按照提示输入用户密码。

createuser --createdb --username postgres --no-createrole --no-superuser --pwprompt openerp

(要删除以前自动安装残留的postgresql 里面的 openerp用户 用dropuser openerp)

退出postgres用户shell

exit

4.安装OE的Python依赖包

sudo apt-get install python-dateutil python-docutils python-feedparser python-gdata \

python-jinja2 python-ldap python-libxslt1 python-lxml python-mako python-mock python-openid \

python-psycopg2 python-psutil python-pybabel python-pychart python-pydot python-pyparsing \

python-reportlab python-simplejson python-tz python-unittest2 python-vatnumber python-vobject \

python-webdav python-werkzeug python-xlwt python-yaml python-zsi python-pyPdf

6月6日起 需要 sudo apt-get install python-requests

以及:sudo apt-get install python-passlib

7月9日起

apt-get install python-decorator

3月20日的版本好像报价单也不能打,

需要装 wkhtmltopdf 0.12.0 , gist.github.com/slickplaid/5557321

不过这方法安装好像很费时,等新版本出来再看看,反正正式要用也等正式版吧,或者用2月26日那个版本。

deb安装就搞定,2月26日之后的版本,好像报表这块改动比较多。

源码安装的,也可以下载了2月26日的版本 停掉服务 替换 openerp 目录。

5.安装OE服务器

首先下载OE源码包,这里下载OpenERP8.0最新开发版本

放开目录权限:

sudo chmod -R 777 /opt/openerp

进入目录:

cd /opt/openerp

下载最新的源码包:

wget ightly.openerp.com/trunk/nightly/src/openerp-8.0dev-latest.tar.gz

最新的 odoo源码 应该在 codeload.github.com/odoo/odoo/zip/master

把源文件解压到openerp用户家目录下:

sudo tar xvf openerp-8.0dev-latest.tar.gz

odoo 注意文件名变化 用: unzip master 就好了

把文件的所有者改为openerp用户:

sudo chown -R openerp: *

这里建议把服务器组件的安装目录修改为server,以便于后续修改时不必修改配置文件。

在当前目录创建目录,给目录最大权限,移动刚才解压的目录到server 目录:

sudo mkdir server

sudo chmod -R 777 server

sudo mv -T openerp-8.0dev-20140318-000101 server

(注意这里,目录名"openerp-8.0dev-20140318-000101"会因为你下载的时间不同而有所不同。

也注意odoo 的目录)

注意,比较推荐用git方式下载,

先apt-get install git

然后

git clone github.com/odoo/odoo.git

git pull 进行差异更新

git checkout 8.0(切换到8.0版本)

git checkout 7.0(切换到7.0版本)

6.配置OpenERP服务

复制OE的默认配置文件到/etc/并修改所有者及权限:

sudo cp /opt/openerp/server/install/openerp-server.conf /etc/

sudo chown openerp: /etc/openerp-server.conf

sudo chmod 640 /etc/openerp-server.conf

修改配置文件:

sudo vi /etc/openerp-server.conf

这里需要修改数据库用户的密码,为第四步时设定的密码(这里用password做参考值),并增加日志文件的路径:

[options]

This is the password that allows database operations:

admin_passwd = admin

db_host = 127.0.0.1

db_port = 5432

db_user = openerp

db_password = password

logfile = /var/log/openerp/openerp-server.log

addons_path = /opt/openerp/server/addons

说明:Odoo8 的 addons 目录变位置了,加一句

使用openerp用户shell登录,验证openerp是否已正确安装:

sudo su - openerp -s /bin/bash

/opt/openerp/server/openerp-server

最后一行显示 openerp.service.server: HTTP service (werkzeug) running on 0.0.0.0:8069表明openerp服务器组件已经安装正确,

你可以用从浏览器输入IP:8069来连接oe(其中IP是OE服务器的IP,本机可以用localhost:8069,或者127.0.0.1:8069连接。

此时你可以按Ctr+C停止OE服务。

如果发现错误提示,通常是依赖包没有正确安装。按照第五步的方法安装缺少的依赖包。

7.增加启动脚本

增加启动脚本/etc/init.d/openerp :

sudo vi /etc/init.d/openerp

输入如下内容(可以粘贴复制的),:w 保存:q退出

#!/bin/sh

### BEGIN INIT INFO

# Provides: openerp-server

# Required-Start: $remote_fs $syslog

# Required-Stop: $remote_fs $syslog

# Should-Start: $network

# Should-Stop: $network

# Default-Start: 2 3 4 5

# Default-Stop: 0 1 6

# Short-Description: Enterprise Resource Management software

# Description: Open ERP is a complete ERP and CRM software.

### END INIT INFO

PATH=/bin:/sbin:/usr/bin

DAEMON=/opt/openerp/server/openerp-server

NAME=openerp-server DESC=openerp-server

# Specify the user name (Default: openerp).

USER=openerp

# Specify an alternate config file (Default: /etc/openerp-server.conf).

CONFIGFILE="/etc/openerp-server.conf"

# pidfile

PIDFILE=/var/run/$NAME.pid

# Additional options that are passed to the Daemon.

DAEMON_OPTS="-c $CONFIGFILE"

[ -x $DAEMON ] || exit 0

[ -f $CONFIGFILE ] || exit 0

checkpid() {

[ -f $PIDFILE ] || return 1

pid=`cat $PIDFILE` [ -d /proc/$pid ] &&return 0 return 1

}

case "${1}" in

start)

echo -n "Starting ${DESC}: "

start-stop-daemon --start --quiet --pidfile ${PIDFILE} \

--chuid ${USER} --background --make-pidfile \

--exec ${DAEMON} -- ${DAEMON_OPTS}

echo "${NAME}."

stop)

echo -n "Stopping ${DESC}: "

start-stop-daemon --stop --quiet --pidfile ${PIDFILE} \

--oknodo echo "${NAME}."

restart|force-reload)

echo -n "Restarting ${DESC}: "

start-stop-daemon --stop --quiet --pidfile ${PIDFILE} \

--oknodo

sleep 1

start-stop-daemon --start --quiet --pidfile ${PIDFILE} \

--chuid ${USER} --background --make-pidfile \

--exec ${DAEMON} -- ${DAEMON_OPTS}

echo "${NAME}."

*)

N=/etc/init.d/${NAME}

echo "Usage: ${NAME} {start|stop|restart|force-reload}" >&2

exit 1

esac

exit 0

建立日志文件的目录,并修改权限:

sudo mkdir /var/log/openerp

sudo chown openerp:root /var/log/openerp

sudo chmod +x /etc/init.d/openerp

启动服务并测试脚本是否可以正常工作:

sudo /etc/init.d/openerp start

netstat -at

两个命令之间间隔一段时期,让OE服务器启动,结果中表明有一行

tcp00 *:8069 *:*LISTEN

表明脚本启动OE成功。

使用浏览器web客户端打开,可以进入数据库管理页面。建议在此修改数据库管理员用户密码。

默认的用户名和密码问admin、admin。然后停止openerp:

sudo /etc/init.d/openerp stop

访问日志文件及网络监听,确认服务已经停止:

netstat -at

8.设置开机自动启动:

sudo update-rc.d openerp defaults

查看日志:

less /var/log/openerp/openerp-server.log

创建数据库,开始openerp之旅吧!

注意这个案例源码运行的 openerp 目录在 /opt/openerp/server/openerp ,

所以要添加 扩展 添加 到 /opt/openerp/server/openerp/addons 目录

需要使用 winscp 和自动备份 模块的的,记得放开 权限 sudo chmod -R 777 /opt/openerp/server/openerp/addons

和自动备份模块的相应权限。

更新:下载最新的源码包,停掉服务sudo /etc/init.d/openerp stop

直接用最新的openerp目录覆盖对应目录就好了,

然后再启动服务sudo /etc/init.d/openerp start