1.搭建環境:
系統版本:Linux centos-linux.shared 3.10.0-123.el7.x86_64 #1 SMP Mon Jun 30 12:09:22 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
python版本:Python 3.5.1
1.1.搭建python3環境:
本人在嘗試過后選擇集成環境Anaconda
1.1.1.編譯
# 下載依賴yum install -y ncurses-devel openssl openssl-devel zlib-devel gcc make glibc-devel libffi-devel glibc-static glibc-utils sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-deve# 下載python版本wget https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tgz# 或者使用國內源wget http://mirrors.sohu.com/python/3.5.1/Python-3.5.1.tgzmv Python-3.5.1.tgz /usr/local/src;cd /usr/local/src# 解壓tar -zxf Python-3.5.1.tgz;cd Python-3.5.1# 編譯安裝./configure --prefix=/usr/local/python3.5 --enable-sharedmake && make install# 建立軟鏈接ln -s /usr/local/python3.5/bin/python3 /usr/bin/python3echo "/usr/local/python3.5/lib" > /etc/ld.so.conf.d/python3.5.confldconfig# 驗證python3python3# Python 3.5.1 (default, Oct 9 2016, 11:44:24)# [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux# Type "help", "copyright", "credits" or "license" for more information.# >>># pip/usr/local/python3.5/bin/pip3 install --upgrade pipln -s /usr/local/python3.5/bin/pip /usr/bin/pip# 本人在安裝時出現問題 將pip重裝wget https://bootstrap.pypa.io/get-pip.py --no-check-certificatepython get-pip.py
1.1.2.集成環境anaconda
# 集成環境anaconda(推薦)wget https://repo.continuum.io/archive/Anaconda3-4.2.0-Linux-x86_64.sh# 直接安裝即可./Anaconda3-4.2.0-Linux-x86_64.sh# 若出錯,可能是解壓失敗yum install bzip2
1.2.安裝mariaDB
# 安裝yum -y install mariadb mariadb-server# 啟動systemctl start mariadb# 設置為開機啟動systemctl enable mariadb# 配置密碼 默認為空mysql_secure_installation# 登錄mysql -u root -p# 創建一個用戶 自己設定賬戶密碼CREATE USER 'user_name'@'localhost' IDENTIFIED BY 'user_pass';GRANT ALL PRIVILEGES ON *.* TO 'user_name'@'localhost' WITH GRANT OPTION;CREATE USER 'user_name'@'%' IDENTIFIED BY 'user_pass';GRANT ALL PRIVILEGES ON *.* TO 'user_name'@'%' WITH GRANT OPTION;
1.3.安裝pyspider
本人使用Anaconda
# 搭建虛擬環境sbird python版本3.*conda create -n sbird python=3*# 進入環境source activate sbird# 安裝pyspiderpip install pyspider# 報錯 # it does not exist. The exported locale is "en_US.UTF-8" but it is not supported# 執行 可寫入.bashrcexport LC_ALL=en_US.utf-8export LANG=en_US.utf-8#ImportError: pycurl: libcurl link-time version (7.29.0) is older than compile-time version (7.49.0)conda install pycurl# 退出source deactivate sbird# 若在虛擬機內 出現無法訪問localhost:5000 可關閉防火墻systemctl stop firewalld.service#########直接運行源碼==============mkdir git;cd git# 下載git clone https://github.com/binux/pyspider.git# 安裝/root/anaconda3/envs/sbird/bin/python /root/git/pyspider/run.py
新聞熱點
疑難解答