# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
SSL=/usr/local/ssl
ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
# Andrew Kuchling's zlib module.
# This require zlib 1.1.3 (or later).
# See http://www.gzip.org/zlib/
zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz
4、安装OpenSSL
apt-get install libssl-dev
5、编译安装Python2.7
./configure
make && make install作者: chengyc 时间: 2012-09-25 00:03
为python安装readline模块 (readline模块加载不成功) (2012-05-24 14:42:56)转载▼
标签: 杂谈 分类: 技术文档
今天用户说在使用安装的python时,无法调用readline模块,我尝试了一下,确实如此:
bash-3.00# /proj/application/tools/python7.1_sol/bin/python
Python 2.7.1 (r271:86832, Jul 18 2011, 14:44:34)
[GCC 3.4.3 (csl-sol210-3_4-branch+sol_rpath)] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import readline
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named readline
>>>
>>>
Python build finished, but the necessary bits to build these modules were not found:
_bsddb _sqlite3 _ssl
_tkinter bsddb185 gdbm
linuxaudiodev ossaudiodev
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
Failed to build these modules:
_curses _curses_panel _locale
readline
running build_scripts
creating build/scripts-2.7
copying and adjusting /tmp/Python-2.7.2/Tools/scripts/pydoc -> build/scripts-2.7
copying and adjusting /tmp/Python-2.7.2/Tools/scripts/idle -> build/scripts-2.7
copying and adjusting /tmp/Python-2.7.2/Tools/scripts/2to3 -> build/scripts-2.7
copying and adjusting /tmp/Python-2.7.2/Lib/smtpd.py -> build/scripts-2.7
changing mode of build/scripts-2.7/pydoc from 644 to 755
changing mode of build/scripts-2.7/idle from 644 to 755
changing mode of build/scripts-2.7/2to3 from 644 to 755
changing mode of build/scripts-2.7/smtpd.py from 644 to 755
./install-sh -c -m 644 ./Tools/gdb/libpython.py python-gdb.py
bash-3.00#
这里,我们很清楚的可以看出,readline模块build失败了,我又查看是否build时有相关报错,我发现build过程有下列不明显的报错:
building 'readline' extension
gcc -fPIC -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I. -IInclude -I./Include -I/usr/local/include -I/tmp/Python-2.7.2/Include -I/tmp/Python-2.7.2 -c /tmp/Python-2.7.2/Modules/readline.c -o build/temp.solaris-2.10-sun4u-2.7/tmp/Python-2.7.2/Modules/readline.o
/tmp/Python-2.7.2/Modules/readline.c:758: warning: 'on_completion_display_matches_hook' defined but not used
gcc -shared build/temp.solaris-2.10-sun4u-2.7/tmp/Python-2.7.2/Modules/readline.o -L/usr/lib/termcap -L/usr/local/lib -L. -lreadline -lncurses -lpython2.7 -o build/lib.solaris-2.10-sun4u-2.7/readline.so
Text relocation remains
这个报错类似于python自己的module下,有它定义好的readline编译方式,它和我在config时,指定的readline有所冲突,不知道为什么,build时没法使用。虽然我在configure时,为此增加了很多参数,比如LDFLAGS,比如CPPFLAGS,还比如我vi了setup.py文件,在# Platform-dependent module source and include directories
里定义了readline的位置,但是我们仍无法加载readline。
Vi这个文件,我们找到readline,会发现有简单的说明,并指明如果要定义一个全新的位置,我们可以通过参数修改
# GNU readline. Unlike previous Python incarnations, GNU readline is
# now incorporated in an optional module, configured in the Setup file
# instead of by a configure script switch. You may have to insert a
# -L option pointing to the directory where libreadline.* lives,
# and you may have to change -ltermcap to -ltermlib or perhaps remove
# it, depending on your system -- see the GNU readline instructions.
# It's okay for this to be a shared library, too.
再次编译时,我没有像以前一样去改python的setup.py文件,我们做过多次的测试,只要指定好环境变量,应该很顺利。
./configure --prefix=/proj/application/tools/python-2.7.2/ --enable-shared
Make
Makeinstall
没有任何报错,readline模块也加载正常。
测试:
bash-3.00# cd /proj/application/tools/python-2.7.2/bin/
bash-3.00# ./python
Python 2.7.2 (default, May 24 2012, 11:37:23)
[GCC 3.4.3 (csl-sol210-3_4-branch+sol_rpath)] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>> import readline
>>> import md5
>>>
bash-3.00#
运行正常。 作者: chengyc 时间: 2012-09-25 07:35
Python如何备份目录及目录下的全部内容
2011-05-17 10:04 Coder Lee Coder Lee博客 我要评论(0) 字号:T | T
#虽然版本控制系统更强大,但这个脚本在开发工作中然后很有用。我常常对它进行定制,比如只对某个特定后缀名的文件进行备份;在for file in files 循环的内部加一个适当的测试就行了。如:name, ext = os.path.splitext(file) if ext not in ('.py', '.txt', '.doc'):continue 代码片段首先使用标准库模块os.path的splitext函数来获得文件的扩展名(以一个句号开始),放入局部变量ext中,然后,如果文件拓展名不是我们感兴趣的几个扩展名之一,我们就执行continue语句,进入下一轮循环。
import sys, os, shutil, filecmp
MAXVERSIONS = 100
def backup(tree_top, bakdir_name = 'bakdir'):
for dir, subdirs, files in os.walk(tree_top):
#make sure each dir has subdir called bakdir
backup_dir = os.path.join(dir, bakdir_name)
if not os.path.exists(backup_dir):
os.makedirs(backup_dir)
#stop recurse the backup dir
subdirs[:] = [ d for d in subdirs if d != bakdir_name ]
for file in files:
filepath = os.path.join(dir,file)
destpath = os.path.join(backup_dir, file)
#check if the old version exist
for index in xrange(MAXVERSIONS):
backup = '%s.%2.2d' % (destpath, index)
if not os.path.exists(backup):
break
if index > 0:
#there is no need to backup if the file is the same as the new version
old_backup = '%s.%2.2d' %(destpath, index-1)
abspath = os.path.abspath(filepath)
try:
if os.path.isfile(old_backup) and filecmp.cmp(abspath, old_backup,shallow = False):
continue
except OSError:
pass
try:
shutil.copy(filepath, backup)
except OSError:
pass
#!/usr/bin/python
#****************AUTHOR:www.ourunix.org********************
#****************RELEASE:v1************************
#****************TIME:2011/03/25*******************
#sometimes i will copy sth by change it's name to backup.However such method can not satisfy my require.
#this python script can do the same thing and tar the file in the same time!
#happy to use it!
import sys
import os
import time
#where do you want to backup
target_dir = "/work/backup/"
#target_dir = "/work/backup/" + time.strftime(%Y%m%d)
#the filename you want to backup
today = target_dir + time.strftime('%Y%m%d')
target = today + "/" + sys.argv[1] + ".tar.gz"
#the command
tar_command = "sudo tar -czf %s %s " % (target,sys.argv[1])
print tar_command
#if len(sys.argv) == 1:
# print "Error,no input file"
# sys.exit()
#else:
if not os.path.exists(today):
os.mkdir(today)
print 'Successfully created directory', today
if os.system(tar_command) == 0:
print "%s has backup to %s successfully!"%(sys.argv[1],target)
else:
print sys.argv[1] ,"backup failed!"作者: chengyc 时间: 2012-09-25 07:56
Python中应用shell脚本
日期:2011-12-28 来源: constantina 分享至:
926L
os.symlink(src,dst)
创建符号链接
tempnam([dir[, prefix]])
为创建一个临时文件合理的返回一个唯一的路径名。这将是一个绝对路径路径,以dir目录中可能的目录项命名,或是一个通常的临时文件的位置,如果dir被忽略或为None。如果给定和不为None,prefix被用来给文件名提供一个简短的前缀。应用负责使用由tempnam()返回的路径恰当地创建和管理文件;不提供自动清除。在Unix上,环境变量TMPDIR覆盖dir,在Windows上TMP被使用。这个函数的指定行为依赖于C库的执行;some aspects are underspecified in system documentation.注意:tempnam()的用法是危险的对于符号连接攻击;考虑用tmpfile()(14.1.2节)替代。可用: Macintosh, Unix, Windows。