一、安裝PYTHON 編譯依賴包
1.1 首先安裝gcc編譯器,gcc有些系統版本已經默認安裝,通過 gcc --version 查看,沒安裝的先安裝gcc,
yum -y install gcc glibc make
1.2 安裝其它依賴包,(注:不要缺少,否則有可能安裝python出錯,python3.7.0以下的版本可不裝 libffi-devel )
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel
1.3 下載python源碼包,此處我選擇安裝 python:3.7.4
wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz
1.4 解壓源碼包
tar zxvf Python-3.7.4.tgz
1.5 編譯python
# 新建一個目錄用來存放并安裝python3 程序
mkdir /opt/app/python3.7.4# 切換到解壓包之后的Python3.7.4目錄
cd Python-3.7.4# ./configure 用來生成編譯參數,--prefix 用來指定安裝目錄,此處填寫剛剛創建的絕對路徑/opt/app/python3.7.4
./configure --prefix=/opt/app/python3.7.4# make 為生成二進制安裝文件,make install 用來進行執行安裝。
make && make install
當看到如下文時,證明安裝成功。
Looking in links: /tmp/tmpf2__yj7o
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-19.0.3 setuptools-40.8.0
1.6 創建軟連接
注:軟連接用來生成打開的快捷方式,同時用來區分python2 和 python3。
ln -s /opt/app/python3.7.4/bin/python3.7 /usr/bin/python3.7
ln -s /opt/app/python3.7.4/bin/pip3.7 /usr/bin/pip3.7
1.7 測試是否可用
[root@iZj6cdf4xm0h3m0do5ojkjZ ~]# python3.7 -V
Python 3.7.4
[root@iZj6cdf4xm0h3m0do5ojkjZ ~]# python3.7
Python 3.7.4 (default, Jan 20 2020, 20:02:14)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print("Hello World")
Hello World
>>> exit()
二、 安裝模塊
pip3.7 install requests
更新
pip3.7 install --upgrade pip
pip3.7 install pymysql
pip3.7 install pillow
安裝圖形識別模塊
pip3.7 install tesserocr
注:此時會有報錯
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/opt/app/python3.7.4/include/python3.7m -c tesserocr.cpp -o build/temp.linux-x86_64-3.7/tesserocr.ogcc: error trying to exec 'cc1plus': execvp: No such file or directoryerror: command 'gcc' failed with exit status 1----------------------------------------
ERROR: Command errored out with exit status 1: /opt/app/python3.7.4/bin/python3.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-4e_e9xf2/tesserocr/setup.py'"'"'; __file__='"'"'/tmp/pip-install-4e_e9xf2/tesserocr/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-k1lj6ss7/install-record.txt --single-version-externally-managed --compile Check the logs for full command output.
解決方法:
yum -y install tesseract-devel
yum -y install gcc-c++
再次安裝,無問題
pip3.7 install tesserocr
Looking in indexes: http://mirrors.cloud.aliyuncs.com/pypi/simple/
Collecting tesserocrDownloading http://mirrors.cloud.aliyuncs.com/pypi/packages/e3/77/fb26b321c3b9ce4a47af12b19e85ddbf4d0629adb6552d85276e824e6e51/tesserocr-2.5.0.tar.gz (54kB)|████████████████████████████████| 61kB 44.4MB/s
Installing collected packages: tesserocrRunning setup.py install for tesserocr ... done
Successfully installed tesserocr-2.5.0
pip3.7 install tesseract-ocr