爬虫-scrapy安装(新)
第一步:安装zlib第二步:安装openssl第三步:编译安装python第四步:安装libxml2
-------------------------分析ubuntu里的自带的python------------------------------
$whereis python
首先找到/usr/bin中的
$which python
/usr/bin/python
分析一下带箭头的文件格式
链接的是当前文件夹下的python2.7
链接的是/usr/local/python/bin/python
不带箭头的文件格式:
---------------------------------------------------------------------------------------
第一步:安装build-essential
$sudo apt-get install build-essential
第二步:安装zlib
下载zlib,以zlib128.zip为例
$unzip zlib128.zip
$./configure --help
$sudo ./configure --prefix=/usr/local/zlib --64
$gedit /etc/bash.bashrc
末尾添加
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/zlib/lib/pkgconfig
export PKG_CONFIG_PATH
$gedit /etc/ld.so.conf
末尾添加
/usr/local/zlib/lib
$ldconfig
$gedit /etc/bash.bashrc
[
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/zlib/lib/pkgconfig:/usr/local/openssl/lib/pkgconfig
export PKG_CONFIG_PATH
CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/local/zlib/include:/usr/local/openssl/include/openssl
export CPLUS_INCLUDE_PATH
C_INCLUDE_PATH=$C_INCLUDE_PATH:/usr/local/zlib/include:/usr/local/openssl/include/openssl
export C_INCLUDE_PATH
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/zlib/lib:/usr/local/openssl/lib
export LD_LIBRARY_PATH
LIBRARY_PATH=$LIBRARY_PATH:/usr/local/zlib/lib:/usr/local/openssl/lib
export LIBRARY_PATH
]
因为安装openssl时,需要zlib,便于zlib可以找到路径
【注意:CPLUS_INCLUDE_PATH=路径,其中路径为 pkgconfig文件夹下的.pc文件末尾中的 Libs和Cflags】
LIBRARY_PATH和LD_LIBRARY_PATH是Linux下的两个环境变量,二者的含义和作用分别如下:
LIBRARY_PATH环境变量用于在程序编译期间查找动态链接库时指定查找共享库的路径,例如,指定gcc编译需要用到的动态链接库的目录。设置方法如下(其中,LIBDIR1和LIBDIR2为两个库目录):
export LIBRARY_PATH=LIBDIR1:LIBDIR2:$LIBRARY_PATH
LD_LIBRARY_PATH环境变量用于在程序加载运行期间查找动态链接库时指定除了系统默认路径之外的其他路径,注意,LD_LIBRARY_PATH中指定的路径会在系统默认路径之前进行查找。设置方法如下(其中,LIBDIR1和LIBDIR2为两个库目录):
export LD_LIBRARY_PATH=LIBDIR1:LIBDIR2:$LD_LIBRARY_PATH
举个例子,我们开发一个程序,经常会需要使用某个或某些动态链接库,为了保证程序的可移植性,可以先将这些编译好的动态链接库放在自己指定的目录下,然后按照上述方式将这些目录加入到LD_LIBRARY_PATH环境变量中,这样自己的程序就可以动态链接后加载库文件运行了。
区别与使用:
开发时,设置LIBRARY_PATH,以便gcc能够找到编译时需要的动态链接库。
发布时,设置LD_LIBRARY_PATH,以便程序加载运行时能够自动找到需要的动态链接库
第三步:安装openssl
下载openssl,以openssl-0.9.8zg.tar.gz为例
$tar zxvf openssl-0.9.8zg.tar.gz
$./config --help
$./config --prefix=/usr/local/openssl shared zlib
$gedit Makefile
修改文件中
ZLIB_INCLUDE=/usr/local/zlib/include
LIBZLIB=/usr/local/zlib/lib
$make
$su root
$make install
【
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/zlib/lib/pkgconfig:/usr/local/openssl/lib/pkgconfig
export PKG_CONFIG_PATH
CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/local/zlib/include:/usr/local/openssl/include/openssl
export CPLUS_INCLUDE_PATH
C_INCLUDE_PATH=$C_INCLUDE_PATH:/usr/local/zlib/include:/usr/local/openssl/include/openssl
export C_INCLUDE_PATH
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/zlib/lib:/usr/local/openssl/lib
export LD_LIBRARY_PATH
LIBRARY_PATH=$LIBRARY_PATH:/usr/local/zlib/lib:/usr/local/openssl/lib
export LIBRARY_PATH
#找到动态链接库的路径
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/zlib/lib
export LD_LIBRARY_PATH
#找到静态库的路径
LIBRARY_PATH=$LIBRARY_PATH:/usr/local/zlib/lib
export LIBRARY_PATH
】
第四步:编译安装python【注意编译安装使用root用户,sudo编译安装时会出现一些问题,比如/usr/local/python,安装后发现是系统的python】
$tar zxvf Python
$cd /python/Modules
$gedit Setup.dist
SSL=/usr/local/openssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
$su root
$./configure --prefix=/usr/local/python --enable-shared CFLAGS=-fPIC
$make
$make install
第四步:安装libxml2
___________________________________________安装完成后-----------------------------
------------------------------------------------------
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/zlib/lib/pkgconfig:/usr/local/openssl/lib/pkgconfig:/usr/local/libxml2/lib/pkgconfig:/usr/local/python3.4.3/lib/pkgconfig:/usr/local/python2.7.10/lib/pkgconfig:/usr/local/sqlite/lib/pkgconfig
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/zlib/lib:/usr/local/openssl/lib:/usr/local/libxml2/lib:/usr/local/python3.4.3/lib:/usr/local/python2.7.10/lib:/usr/local/sqlite/lib
export LD_LIBRARY_PATH
LIBRARY_PATH=$LIBRARY_PATH:/usr/local/zlib/lib:/usr/local/openssl/lib:/usr/local/python3.5.0/lib:/usr/local/libxml2/lib:/usr/local/python3.4.3/lib:/usr/local/python2.7.10/lib:/usr/local/sqlite/lib
export LIBRARY_PATH
CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/local/zlib/include:/usr/local/openssl/include:/usr/local/libxml2/include/libxml2:/usr/local/python3.4.3/include/python3.4m:/usr/local/python2.7.10/include:/usr/local/sqlite/include
export CPLUS_INCLUDE_PATH
C_INCLUDE_PATH=$C_INCLUDE_PATH:/usr/local/zlib/include:/usr/local/openssl/include:/usr/local/libxml2/include/libxml2:/usr/local/python3.4.3/include/python3.4m::/usr/local/python2.7.10/include:/usr/local/sqlite/include
export C_INCLUDE_PATH
PATH=$PATH:/usr/local/openssl/bin:/usr/local/libxml2/bin:/usr/local/python2.7.10/bin:/usr/local/sqlite/bin
export PATH
更多推荐
所有评论(0)