#安装Scarpy踩过的坑

Scrapy是python下一个著名的爬虫,目前最新版为0.24。

这是他的帮助文档->Scrapy 0.24 文档

其中**选择器篇**需要好好研究!

帮助文档里的安装指南写得很宽泛,所以安装出错是在正常不过的事了。(再者说,安装出错确实不是Scrapy的错嘛)

So here is the doc to help you with installing Scrapy.

First of all, before installing, please make sure U have already installed these libs or apps below:

  • python version >= 2.7
  • python-devel package
  • libs:
    1. xml2-dev
    2. xslt-dev
    3. ffi-dev
    4. openssl-dev

If not, commands below may help:

on Redhat/Centos:

yum install python-devel libxml2-devel libxslt-devel libffi-devel openssl-devel bzip2-devel 

on Debian/Ubuntu:

apt-get install python-dev libxml2-dev libxslt1-dev libffi-dev libssl-dev libbz2-dev

If your python version is less than 2.7, this article -> upgrade python may help U in upgrading python.

I have summarized some errors when installing scrapy and hope they can be used as a reference for you.

CompressionError: bz2 module is not available

This usually happens when you have compiled python and use pip install Scrapy command.

The reason is you don't have bzip2 lib installed:

on Redhat/Centos:

yum install bzip2-devel 

on Debian/Ubuntu:

apt-get install libbz2-dev

After you have installed the bzip2 package,you have to compile python again to make bzip module work.

Finally,use pip install --upgrade scrapy to finish the installation.

Setup script exited with error: command 'gcc' failed with exit status 1

The cause is u didn't install python-dev

on Redhat/Centos:

yum install python-devel

on Debian/Ubuntu:

apt-get install python-dev

Finally,use pip install scrapy or easy_install scrapy to finish the installation.

error: Not a recognized archive type: /tmp/easy_install-dayrGH/Twisted-14.0.0.tar.bz2

Haha,that's because you already have installed the package!

UserWarning: You do not have the service_identity module installed.

sudo pip install service_identity

That's all for now.Thank u for viewing.

自从用了Shadowsocks,整个人都精神多了!

今天开整Dropbox,话说这货也被Q了。

废话不多说

以下内容需要翻{防屏蔽}墙使用,如果没有,可以参考老高的这篇文章搭建一个稳定又极速的翻{防屏蔽}墙环境

下载

官网找到linux专用脚本,执行一下对应系统的脚本

32位系统

cd ~ && wget -O - "https://www.dropbox.com/download?plat=lnx.x86" | tar xzf -

64位系统

cd ~ && wget -O - "https://www.dropbox.com/download?plat=lnx.x86_64" | tar xzf -

阅读剩余部分

python交互模式下方向键乱码的正确解决方法

今天升级了python后,发现在交互模式中上下左右变成了乱码

^[[A ^[[D ^[[B ^[[C ^[[D ^[[D ^[[D ^[[D ^[[D ^[[D ^[[D ^[[D 

搜索了一下,普遍的解决方法是

因为方向键被转义了 原因主要是由于缺少readline Module问题导致的。而CentOS默认只有readline模块而没有readline-devel模块。

解决方法 yum -y install readline-devl 然后重新编译安装python就ok了

再仔细一看,这些问题都是N年前了,yum中的包名早都换了。。。怪不得总是报错,说找不到readline-devl,貌似现在开发版后面都变成devel

阅读剩余部分

bad interpreter: 没有那个文件或目录

起因

今天在linux上运行一个python脚本,总是报错bad interpreter,开始我以为是解释器的路径问题,可是whereis python告诉我路径没有错!

google之,问题解决:

在windows上编辑的脚本,到linux上执行,会提示上面的错误

解决办法

dos2unix myfilename

报错的话执行一下yum install dos2unix -y

原因

在windows下编辑的脚本,是dos格式的,即每一行的行尾以\r\n来标识, 其ASCII码分别是0x0D, 0x0A。

以后再windows上的写脚本一定要三思!

今天写了个采集脚本,使用了BeautifulSoup,所以在代码中有下面的import语句

from BeautifulSoup import BeautifulSoup as BS

在win下执行,没问题,但是在linux下执行,就报这个错误

ImportError: No module named BeautifulSoup

google之

转自快乐&&平凡

脚本语言的第一行,目的就是指出,你想要你的这个文件中的代码用什么可执行程序去运行它,就这么简单

#!/usr/bin/python是告诉操作系统执行这个脚本的时候,调用/usr/bin下的python解释器;
#!/usr/bin/env python这种用法是为了防止操作系统用户没有将python装在默认的/usr/bin路径里。当系统看到这一行的时候,首先会到env设置里查找python的安装路径,再调用对应路径下的解释器程序完成操作。
#!/usr/bin/python相当于写死了python路径;
#!/usr/bin/env python会去环境设置寻找python目录,推荐这种写法。

而我的/usr/bin/python是2.6版本,但是安装BeautifulSoup的是2.7。。。

#mv /usr/bin/python /usr/bin/python2.6.6
#ln -s /usr/local/bin/python2.7 /usr/bin/python

成功解决!