
Python
rwen001
cookbook
展开
-
CENTOS 6.5 安装 Python 2.7 总结
CENTOS 6.X 系列默认安装的 Python 2.6 ,目前开发中主要是使用 Python 2.7 ,这两个版本之间还是有不少差异的,程序在 Python 2.6 下经常会出问题。比如: re.sub 函数 ,2.7 支持 flags 参数,而 2.6 却不支持。所以,打算安装 Python 2.7 来运行 Flask 应用程序,但 2.6 不能删除,因为系统对它有依赖。转载 2016-01-28 17:51:23 · 2589 阅读 · 0 评论 -
beautifulsoup官方文档
indexBeautiful Soup 4.2.0 documentation »Beautiful Soup 4.2.0 文档Beautiful Soup 是一个可以从HTML或XML文件中提取数据的Python库.它能够通过你喜欢的转换器实现惯用的文档导航,查找,修改文档的方式.Beautiful Soup会帮你节省数小时甚至数天的工作时间.这篇转载 2014-10-27 07:45:44 · 3782 阅读 · 1 评论 -
使用Fabric部署网站应用
以前一直用rsync同步代码到服务器,这种山寨方法用一次两次还可,每天部署10次就麻烦了,最近抽空研究了一下Fabric,发现这个东西部署起来简直太爽了。Fabric是一个用Python开发的部署工具,最大特点是不用登录远程服务器,在本地运行远程命令,几行Python脚本就可以轻松部署。花10分钟写了一个部署脚本fabfile.py(名字不能变),放到工程目录下:#!/usr/bin/转载 2014-10-24 16:55:34 · 850 阅读 · 0 评论 -
Python内置函数进制转换的用法
使用Python内置函数:bin()、oct()、int()、hex()可实现进制转换。先看Python官方文档中对这几个内置函数的描述:bin(x)Convert an integer number to a binary string. The result is a valid Python expression. If x is not a Python int obj转载 2014-09-04 07:02:06 · 3351 阅读 · 1 评论 -
Understanding Python's "with" statement
http://effbot.org/zone/python-with-statement.htmFredrik Lundh | October 2006 | Originally posted to online.effbot.orgJudging from comp.lang.python and other forums, Python 2.5’s转载 2014-09-17 09:50:05 · 560 阅读 · 0 评论 -
django改变或添加admin后台的用户密码
>>> from django.contrib.auth.models import User>>> u = User.objects.get(username__exact='john')>>> u.set_password('new password')>>> u.save()原创 2014-09-03 17:21:04 · 9313 阅读 · 1 评论 -
Minimal Nginx and Gunicorn configuration for Django projects
http://agiliq.com/blog/2013/08/minimal-nginx-and-gunicorn-configuration-for-djang/转载 2014-09-16 14:02:14 · 742 阅读 · 0 评论 -
Supervisor with Django and Gunicorn
forked from : https://agiliq.com/blog/2014/05/supervisor-with-django-and-gunicorn/转载 2014-09-16 13:52:27 · 920 阅读 · 0 评论 -
How to install PIL in Ubuntu 11.04?
As always, use the package manager:sudo apt-get install python-imagingIt'll deal with it all for you. The packages are available.Manually installing, in any Linux distro, is a wasted endea转载 2014-08-19 17:34:53 · 604 阅读 · 0 评论 -
No module named _sqlite3
This is what I did to get it to work.I am using pythonbrew(which is using pip) with python 2.7.5 installed.I first did what Zubair(above) said and ran this command:sudo apt-get install libsq转载 2014-08-19 09:40:25 · 520 阅读 · 0 评论 -
Django异常 - ImportError: No module named django.core.management
Django错误 - ImportError: No module named django.core.management问题描述:在命令行输入 manage.py runserver,提示找不到django.core.management模块。问题分析:1. 确定Django已安装,进行Django的安装目录查看,django.core.management确实存在2.转载 2014-08-18 22:11:52 · 1732 阅读 · 0 评论 -
Setting up Django with Nginx, Gunicorn, virtualenv, supervisor and PostgreSQL
http://michal.karzynski.pl/blog/2013/06/09/django-nginx-gunicorn-virtualenv-supervisor/转载 2014-09-23 16:32:01 · 1476 阅读 · 0 评论 -
python 检测内存溢出
收集了些可以用于检测 python程序的内存溢出检测模块:原创 2014-09-12 08:13:17 · 3622 阅读 · 0 评论 -
python中那些双下划线开头得函数和变量
python中以双下划线的是一些系统定义得名称,让python以更优雅得语法实行一些操作,本质上还是一些函数和变量,与其他函数和变量无二。比如x.__add__(y) 等价于 x+y有一些很常见,有一些可能比较偏,在这里罗列一下,做个笔记,备忘。x.__contains__(y) 等价于 y in x, 在list,str, dict,set等容器中有这个函数__base__, _转载 2014-08-15 09:58:07 · 650 阅读 · 0 评论 -
安装python包出错时的一般解决办法
经常做python开发,大量安装形形色色的python第三方库是在所难免的如:原创 2014-08-26 10:35:58 · 3716 阅读 · 0 评论 -
CentOS 6.5 安装 Python3 and install virtualenv3
http://linux.it.net.cn/CentOS/course/2015/1010/17718.html安装环境 yum install gcc yum install zlib-devel yum install make 下载python版本 wget http://www.python.org/ftp/python/3原创 2016-03-25 11:15:47 · 957 阅读 · 0 评论 -
Python pip 更新问题汇总
http://www.cnblogs.com/leisurely/p/4582328.htmllibxml/xmlversion.h: No such file or directorysudo apt-get install libxml2-dev libxslt1-devEnvironmentError: mysql_config not fou转载 2016-01-09 23:20:54 · 1608 阅读 · 0 评论 -
error: Unable to find vcvarsall.bat
http://blog.youkuaiyun.com/secretx/article/details/17472107如果你安装的是 2012 版:在运行insall 命令之前先运行下面的: SET VS90COMNTOOLS=%VS110COMNTOOLS%转载 2015-12-22 22:57:29 · 571 阅读 · 0 评论 -
Python教程:numpy的基本介绍
先决条件在阅读这个教程之前,你多少需要知道点python。如果你想重新回忆下,请看看Python Tutorial.如果你想要运行教程中的示例,你至少需要在你的电脑上安装了以下一些软件:PythonNumPy这些是可能对你有帮助的:ipython是一个净强化的交互Python Shell,对探索NumPy的特性非常方便。matplotlib将允许你绘图S转载 2016-01-02 23:17:31 · 846 阅读 · 0 评论 -
UnicodeDecodeError : 'ascii' codec can't decode byte 0xe0 in position 0: ordinal not in range(128)
UnicodeDecodeError : 'ascii' codec can't decode byte 0xe0 in position 0: ordinal not in range(128)http://stackoverflow.com/questions/4237898/unicodedecodeerror-ascii-codec-cant-decod原创 2015-12-30 14:02:25 · 845 阅读 · 0 评论 -
解决pyqt 打包成py2exe后在界面正常显示jpeg的问题
本来以为写好代码,直接使用py2exe打包后就一切大功告成,谁知道PyQt4中QPixmap.load图片后,只能正常显示PNG格式的图片(原来这个是QT默认支持的图片格式),加载JPEG格式图片都返回QPixmap is NULL ,查了很多相关问题,试了解决方案,都不奏效,最后辛亏去翻了一下py2exe的论坛(http://www.py2exe.org/index.cgi/Py2exe转载 2015-10-20 09:42:15 · 1405 阅读 · 0 评论 -
ImportError: cannot import name IncompleteRead
在ubuntu上运行sudo pip install xxx ,出现如下错误:s99a@crawler:~$ pipTraceback (most recent call last): File "/usr/bin/pip", line 9, in load_entry_point('pip==1.5.4', 'console_scripts', 'pip')()原创 2015-10-16 20:53:52 · 3789 阅读 · 0 评论 -
第一次向pypi添加一个新的库
原创地址: http://jamie.curle.io/posts/my-first-experience-adding-package-pypi/I’ve used PyPi to download but up until today I’d never actually uploaded a package to it. Today, however, is an转载 2015-10-16 21:22:00 · 482 阅读 · 0 评论 -
Python中dict详解
转载地址:http://blog.youkuaiyun.com/tianmohust/article/details/7621424#字典的添加、删除、修改操作dict = {"a" : "apple", "b" : "banana", "g" : "grape", "o" : "orange"}dict["w"] = "watermelon"del(dict["a"])d转载 2015-08-27 17:53:04 · 592 阅读 · 0 评论 -
在PyQt里面如何做长操作时同时更新GUI
http://hgoldfish.com/blogs/article/78/类型:Python,C++ & Qt4,创建时间:一月 17, 2012, 3:53 p.m.标题无“转载”即原创文章,版权所有。转载请注明来源:http://hgoldfish.com/blogs/article/78/。经常看到有人问在PyQt里面如何做长操作的时候更转载 2015-05-25 21:43:17 · 5645 阅读 · 0 评论 -
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
sudo apt-get install libevent-devsudo apt-get install python-devsudo apt-get install python-twisted-web python2.7-dev安装 pip :$ wget https://bootstrap.pypa.io/get-pip.py.原创 2014-12-30 23:11:55 · 60219 阅读 · 1 评论 -
setuptools,pip,install,UnicodeDecodeError: 'ascii' codec can't decode byte.原因和解决方案
转载地址:http://blog.youkuaiyun.com/hugleecool/article/details/17996993昨天重装Python2.7.6时,为了安装第三方库,我去下pip。为了装pip,又得先装 ez_setup.py。结果装ez_setup时,遇到了问题,报错:[html] view plaincopyU转载 2015-01-12 16:13:55 · 1402 阅读 · 0 评论 -
在windows上面 安装virtualenv 和fabric
fabric installs just fine on Windows, but you will need to either: have a compiler installed to build the pycrypto dependency during setup.If you don't have one already, install MinGW or you原创 2014-11-13 17:45:22 · 1118 阅读 · 0 评论 -
ImportError: No module named _sqlite3
I had the same problem (building python2.5 from source on Ubuntu Lucid), andimport sqlite3 threw this same exception. I've installed libsqlite3-dev from the package manager, recompiled python2.5, an转载 2014-09-19 11:38:41 · 2978 阅读 · 0 评论 -
Getting Started with Solr 4.9 and Django haystack
forked from : http://www.alexanderinteractive.com/blog/2012/08/getting-started-with-solr-and-django/转载 2014-08-22 07:42:01 · 1071 阅读 · 0 评论 -
UnicodeEncodeError: 'ascii' codec can't encode characters in position
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-5: ordinal not in range(128)原创 2014-09-05 10:20:46 · 1660 阅读 · 0 评论 -
django自带的server能让外网主机访问
http://hi.baidu.com/xiaoxifeng_01/item/a030163c2434c5e1392ffa05django自带的server能让外网主机访问django自带的server能让外网主机访问django自带的server能让外网主机访问命令:python manage.py runserver 9.115.120.81:8转载 2013-09-29 16:30:25 · 19386 阅读 · 2 评论 -
AttributeError: 'module' object has no attribute 的解决方法
AttributeError: 'module' object has no attribute "funSalaryGuide"这个错误相信很多django的开发人员都会遇到。一般来说都是应用没有安装完成,重新安装就可以了。这几天我遇到的情况是已经写好并且用了好几个月的组件,会在某一次出现这个情况,然后就一直这个情况,重新编译文件,重启服务器,重启电脑,均没有效果有一次这个错误我通过在i转载 2013-08-30 13:30:33 · 5307 阅读 · 0 评论 -
微信机器人:小蜗牛有道翻译小助手——Django + SAE + 微信公众帐号自动回复开放接口
序 某一天上着多核程序设计的课上,无聊刷rss,偶然看见一片文章,一个哥们用微信公众帐号自动回复接口和php写了一个自动翻译的机器人,让我眼前一亮,我决定自己动手做一个,技术上选了Django,服务器用的是SAE。==Update==本项目源码:https://github.com/liushuaikobe/littlesnailFork me:https://github.co转载 2013-08-27 10:23:44 · 1651 阅读 · 0 评论 -
python crawler(1)
学用python也有3个多月了,用得最多的还是各类爬虫脚本:写过抓代理本机验证的脚本,写过在discuz论坛中自动登录自动发贴的脚本,写过自动收邮件的脚本,写过简单的验证码识别的脚本,本来想写google music的抓取脚本的,结果有了强大的gmbox,也就不用写了。-这些脚本有一个共性,都是和web相关的,总要用到获取链接的一些方法,再加上simplecd这个半爬虫半网站的项目,累积不转载 2013-08-25 07:29:45 · 661 阅读 · 0 评论 -
UnicodeDecodeError: 'utf8' codec can't decode byte
最近老是出现如题这样的错误,本来解析的就是utf-8编码的字符,但是页面显示时就报这个错误,在网上找了半天,结果都说是字符集选得不对,不论对字符做encode,还是decode都出错,最后终于找到问题,原来是我对字符做了一个截取的操作,因为页面显示一段文本时只显示100个中文字,我就用了s[:100],这就是问题的根源所在,因为串里面有中文有英文,所以当这样截取的时候可能会把一个中文字符截出一半,原创 2013-08-24 23:41:26 · 1107 阅读 · 0 评论 -
python2.7.2的安装
1、下载可从 http://www.python.org/进行下载wget http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tar.bz22、解压tar jxvf Python-2.7.2.tar.bz23.进入目录安装:./configure --prefix=/usr/local/Python2.7 --ena转载 2013-08-23 07:20:23 · 1096 阅读 · 0 评论 -
Python字符串的encode与decode研究心得乱码问题解决方法
为什么Python使用过程中会出现各式各样的乱码问题,明明是中文字符却显示成“\xe4\xb8\xad\xe6\x96\x87”的形式?为什么会报错“UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)”?本文就来研究一下这个问题。字符串在转载 2013-08-22 20:17:08 · 686 阅读 · 0 评论 -
PIL IOError: decoder jpeg not available
#IOError: decoder jpeg not available #Fix: #First remove your last install! rm -rf /usr/lib/python2.4/site-packages/PIL rm /usr/lib/python2.4/site-packages/PIL.pth rm ~/Imaging-1.1.6 #Make sur转载 2013-07-26 03:31:06 · 1218 阅读 · 0 评论 -
sqlalchemy.exc.OperationalError: (OperationalError) could not connect to server: Connection refused
最近在用FLASK开发一个网站,从github上面clone了一个小例子,用的数据库是postgresql,当数据库服务没有打开时,会报以下错误():Traceback (most recent call last): File "/root/workspace_aptana/flask/flask-bootstrap/app.py", line 86, in d原创 2013-05-30 06:07:34 · 9745 阅读 · 0 评论