#第1步:安装Anaconda
- wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2021.05-Linux-x86_64.sh
- sh Anaconda3-2021.05-Linux-x86_64.sh;
- 一路回车(ENTER),直到看见yes;
- 输入yes回车后,此时光标处输入目标路径即为你要自定义的安装路径了
- 将conda加入环境变量
- vim ~/.bashrc
- 先按i进入编辑模式
在第一行输入:
export PATH=“~/anaconda3/bin:$PATH”
若安装时自定义了安装位置,则将~/anaconda3/bin改为自定义的安装目录下的bin文件夹 - 修改后的~/.bash_profile文件应如下(其中xxx为用户名):
# 修改后的~/.bash_profile文件应如下(其中xxx为用户名): export PATH="~/opt/anaconda3/bin:$PATH" # >>> conda initialize >>> # !! Contents within this block are managed by 'conda init' !! __conda_setup="$('/Users/xxx/opt/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)" if [ $? -eq 0 ]; then eval "$__conda_setup" else if [ -f "/Users/xxx/opt/anaconda3/etc/profile.d/conda.sh" ]; then . "/Users/xxx/opt/anaconda3/etc/profile.d/conda.sh" else export PATH="/Users/xxx/opt/anaconda3/bin:$PATH" fi fi unset __conda_setup # <<< conda initialize <<<
- 验证是否能识别conda命令
在终端中输入source ~/.bash_profile以更新环境变量
再在终端输入conda info --envs,若能显示当前有base环境,则conda已加入环境变量
第2步:创建conda环境
- 创建新的conda环境
- 设置下载源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/ conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/ conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/ conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/ conda config --add channels https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main/ conda config --add channels https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/free/ conda config --add channels https://mirrors.sjtug.sjtu.edu.cn/anaconda/cloud/conda-forge/
- 设置搜索时显示通道地址 从channel中安装包时显示channel的url,这样就可以知道包的安装来源
conda config --set show_channel_urls yes
- 在命令行输入以下命令,创建名为paddle_env的环境
# 此处为加速下载,paddle_env conda create --name paddle_env python=3.8
- 之后命令行中会输出提示信息,输入y并回车继续安装
- 激活刚创建的conda环境,在命令行中输入以下命令
# 激活paddle_env环境 conda activate paddle_env
- 以上anaconda环境和python环境安装完毕
#第3步:安装模型
- 安装Paddle程序所需要库
pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple
pip install paddlehub -i https://mirror.baidu.com/pypi/simple
- 环境依赖
- 该Module依赖于第三方库shapely和pyclipper,使用该Module之前,请先安装shapely和pyclipper。
pip install shapely pyclipper
- 安装
hub install chinese_ocr_db_crnn_server
#第4步:安装OCR识别服务
- 安装flask
pip3 install flask
- 安装flask-restful
pip3 install flask-restful
- 安装flasgger
- 注意:需要更新setuptools
pip3 install -U setuptools
pip3 install flasgger
- 管理数据库的依赖
pip3 install flask_script
pip3 install flask_migrate
5.安装FastAPI python web 框架
pip install fastapi
pip install "uvicorn[standard]"
-
编辑python web 开放接口
-
授权
chmod u+x 文件名
#第5步: 部署
- 安装Gunicorn
pip install gunicorn
+ 查看帮助
gunicorn -h
- 以命令行方式启动应用
gunicorn main:app -b 0.0.0.0:6699 -w 4 -k uvicorn.workers.UvicornWorker --daemon --error ocr.log
前台运行:uvicorn main:app --reload
- 获取Gunicorn进程树
pstree -ap | grep gunicorn
- 终止Gunicorn任务
pkill -f gunicorn