environment_en.md 14.7 KB
Newer Older
qq_25193841's avatar
qq_25193841 已提交
1 2
# Environment Preparation

L
LDOUBLEV 已提交
3 4 5 6 7 8
Recommended working environment:
- PaddlePaddle >= 2.0.0 (2.1.2)
- python3.7
- CUDA10.1 / CUDA10.2
- CUDNN 7.6

qq_25193841's avatar
qq_25193841 已提交
9 10 11 12 13
* [1. Python Environment Setup](#1)
  + [1.1 Windows](#1.1)
  + [1.2 Mac](#1.2)
  + [1.3 Linux](#1.3)
* [2. Install PaddlePaddle 2.0](#2)
L
LDOUBLEV 已提交
14 15
* [3. Install PaddleOCR Dependencies](#3)

qq_25193841's avatar
qq_25193841 已提交
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37

<a name="1"></a>

## 1. Python Environment Setup

<a name="1.1"></a>

### 1.1 Windows

#### 1.1.1 Install Anaconda

- Note: To use paddlepaddle you need to install python environment first, here we choose python integrated environment Anaconda toolkit

  - Anaconda is a common python package manager
  - After installing Anaconda, you can install the python environment, as well as numpy and other required toolkit environment.

- Anaconda download.

  - Address: https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/?C=M&O=D

  - Most Win10 computers are 64-bit operating systems, choose x86_64 version; if the computer is a 32-bit operating system, choose x86.exe

38
    <img src="../install/windows/Anaconda_download.png" alt="anaconda download" width="800" align="center "/>
qq_25193841's avatar
qq_25193841 已提交
39 40 41 42 43 44 45 46 47

  - After the download is complete, double-click the installer to enter the graphical interface

  - The default installation location is C drive, it is recommended to change the installation location to D drive.

    <img src="../install/windows/anaconda_install_folder.png" alt="install config" width="500" align=" left"/>

  - Check conda to add environment variables and ignore the warning that

48
    <img src="../install/windows/anaconda_install_env.png" alt="add conda to path" width="500" align="center"/>
L
LDOUBLEV 已提交
49

qq_25193841's avatar
qq_25193841 已提交
50 51 52 53 54

#### 1.1.2 Opening the terminal and creating the conda environment

- Open Anaconda Prompt terminal: bottom left Windows Start Menu -> Anaconda3 -> Anaconda Prompt start console

55
  <img src="../install/windows/anaconda_prompt.png" alt="anaconda download" width="300" align="center"/>
qq_25193841's avatar
qq_25193841 已提交
56 57 58 59 60 61 62 63 64 65 66 67 68 69


- Create a new conda environment

  ```shell
  # Enter the following command at the command line to create an environment named paddle_env
  # Here to speed up the download, use the Tsinghua source
  conda create --name paddle_env python=3.8 --channel https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ # This is a one line command
  ```

  This command will create an executable environment named paddle_env with python version 3.8, which will take a while depending on the network status

  The command line will then output a prompt, type y and enter to continue the installation

70
  <img src="../install/windows/conda_new_env.png" alt="conda create" width="700" align="center"/>
qq_25193841's avatar
qq_25193841 已提交
71 72 73 74 75 76 77 78 79

- To activate the conda environment you just created, enter the following command at the command line.

  ```shell
  # Activate the paddle_env environment
  conda activate paddle_env
  # View the current location of python
  where python
  ```
L
LDOUBLEV 已提交
80

81
  <img src="../install/windows/conda_list_env.png" alt="create environment" width="600" align="center"/>
qq_25193841's avatar
qq_25193841 已提交
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101

The above anaconda environment and python environment are installed



<a name="1.2"></a>

### 1.2 Mac

#### 1.2.1 Installing Anaconda

- Note: To use paddlepaddle you need to install the python environment first, here we choose the python integrated environment Anaconda toolkit

  - Anaconda is a common python package manager
  - After installing Anaconda, you can install the python environment, as well as numpy and other required toolkit environment

- Anaconda download:.

  - Address: https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/?C=M&O=D

102
  <img src="../install/mac/anaconda_start.png" alt="anaconda download" width="800" align="center"/>
qq_25193841's avatar
qq_25193841 已提交
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143

  - Select `Anaconda3-2021.05-MacOSX-x86_64.pkg` at the bottom to download

- After downloading, double click on the .pkg file to enter the graphical interface

  - Just follow the default settings, it will take a while to install

- It is recommended to install a code editor such as vscode or pycharm

#### 1.2.2 Open a terminal and create a conda environment

- Open the terminal

  - Press command and spacebar at the same time, type "terminal" in the focus search, double click to enter terminal

- **Add conda to the environment variables**

  - Environment variables are added so that the system can recognize the conda command

  - Open `~/.bash_profile` in the terminal by typing the following command.

    ```shell
    vim ~/.bash_profile
    ```

  - Add conda as an environment variable in `~/.bash_profile`.

    ```shell
    # Press i first to enter edit mode
    # In the first line type.
    export PATH="~/opt/anaconda3/bin:$PATH"
    # If you customized the installation location during installation, change ~/opt/anaconda3/bin to the bin folder in the customized installation directory
    ```

    ```shell
    # The modified ~/.bash_profile file should look like this (where xxx is the username)
    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
L
LDOUBLEV 已提交
144
            eval "$__conda_setup"
qq_25193841's avatar
qq_25193841 已提交
145
    else
L
LDOUBLEV 已提交
146 147 148 149 150
            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
qq_25193841's avatar
qq_25193841 已提交
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
    fi
    unset __conda_setup
    # <<< conda initialize <<<
    ```

    - When you are done, press `esc` to exit edit mode, then type `:wq!` and enter to save and exit

  - Verify that the conda command is recognized.

    - Enter `source ~/.bash_profile` in the terminal to update the environment variables
    - Enter `conda info --envs` in the terminal again, if it shows that there is a base environment, then conda has been added to the environment variables

- Create a new conda environment

  ```shell
  # Enter the following command at the command line to create an environment called paddle_env
  # Here to speed up the download, use Tsinghua source
  conda create --name paddle_env python=3.8 --channel https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  ```

  - This command will create an executable environment named paddle_env with python version 3.8, which will take a while depending on the network status

  - The command line will then output a prompt, type y and enter to continue the installation

175
    - <img src="../install/mac/conda_create.png" alt="conda_create" width="600" align="center"/>
qq_25193841's avatar
qq_25193841 已提交
176 177 178 179 180 181 182 183 184 185

- To activate the conda environment you just created, enter the following command at the command line.

  ```shell
  # Activate the paddle_env environment
  conda activate paddle_env
  # View the current location of python
  where python
  ```

186
  <img src="../install/mac/conda_activate.png" alt="conda_actviate" width="600" align="center"/>
qq_25193841's avatar
qq_25193841 已提交
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207

The above anaconda environment and python environment are installed

<a name="1.3"></a>



### 1.3 Linux

Linux users can choose to run either Anaconda or Docker. If you are familiar with Docker and need to train the PaddleOCR model, it is recommended to use the Docker environment, where the development process of PaddleOCR is run. If you are not familiar with Docker, you can also use Anaconda to run the project.

#### 1.3.1 Anaconda environment configuration

- Note: To use paddlepaddle you need to install the python environment first, here we choose the python integrated environment Anaconda toolkit

  - Anaconda is a common python package manager
  - After installing Anaconda, you can install the python environment, as well as numpy and other required toolkit environment

- **Download Anaconda**.

  - Download at: https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/?C=M&O=D
L
LDOUBLEV 已提交
208

qq_25193841's avatar
qq_25193841 已提交
209

210
  <img src="../install/linux/anaconda_download.png" akt="anaconda download" width="800" align="center"/>
qq_25193841's avatar
qq_25193841 已提交
211

L
LDOUBLEV 已提交
212

qq_25193841's avatar
qq_25193841 已提交
213 214 215 216 217 218 219 220 221 222 223 224 225 226

  - Select the appropriate version for your operating system
      - Type `uname -m` in the terminal to check the command set used by your system

  - Download method 1: Download locally, then transfer the installation package to the linux server

  - Download method 2: Directly use linux command line to download

    ```shell
    # First install wget
    sudo apt-get install wget # Ubuntu
    sudo yum install wget # CentOS
    ```
    ```bash
L
LDOUBLEV 已提交
227
    # Then use wget to download from Tsinghua source
qq_25193841's avatar
qq_25193841 已提交
228 229 230 231
    # If you want to download Anaconda3-2021.05-Linux-x86_64.sh, the download command is as follows
    wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2021.05-Linux-x86_64.sh
    # If you want to download another version, you need to change the file name after the last 1 / to the version you want to download
    ```
L
LDOUBLEV 已提交
232

qq_25193841's avatar
qq_25193841 已提交
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
- To install Anaconda.

  - Type `sh Anaconda3-2021.05-Linux-x86_64.sh` at the command line
    - If you downloaded a different version, replace the file name of the command with the name of the file you downloaded
  - Just follow the installation instructions
    - You can exit by typing q when viewing the license

- **Add conda to the environment variables**

  - If you have already added conda to the environment variable path during the installation, you can skip this step

  - Open `~/.bashrc` in a terminal.

    ```shell
    # Enter the following command in the terminal.
    vim ~/.bashrc
    ```

  - Add conda as an environment variable in `~/.bashrc`.

    ```shell
    # Press i first to enter edit mode # In the first line enter.
    export PATH="~/anaconda3/bin:$PATH"
    # If you customized the installation location during installation, change ~/anaconda3/bin to the bin folder in the customized installation directory
    ```

     ```shell
    # The modified ~/.bash_profile file should look like this (where xxx is the username)
    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 <<<
     ```

    - When you are done, press `esc` to exit edit mode, then type `:wq!` and enter to save and exit

  - Verify that the conda command is recognized.

    - Enter `source ~/.bash_profile` in the terminal to update the environment variables
    - Enter `conda info --envs` in the terminal again, if it shows that there is a base environment, then conda has been added to the environment variables

- Create a new conda environment

  ```shell
  # Enter the following command at the command line to create an environment called paddle_env
  # Here to speed up the download, use Tsinghua source
  conda create --name paddle_env python=3.8 --channel https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  ```

  - This command will create an executable environment named paddle_env with python version 3.8, which will take a while depending on the network status

  - The command line will then output a prompt, type y and enter to continue the installation

297
    <img src="../install/linux/conda_create.png" alt="conda_create" width="500" align="center"/>
qq_25193841's avatar
qq_25193841 已提交
298 299 300 301 302 303 304 305 306 307

- To activate the conda environment you just created, enter the following command at the command line.

  ```shell
  # Activate the paddle_env environment
  conda activate paddle_env
  ```

The above anaconda environment and python environment are installed

308

qq_25193841's avatar
qq_25193841 已提交
309 310 311 312 313 314 315 316 317 318
#### 1.3.2 Docker environment preparation

**The first time you use this docker image, it will be downloaded automatically. Please be patient.**

```bash
# Switch to the working directory
cd /home/Projects
# You need to create a docker container for the first run, and do not need to run the current command when you run it again
# Create a docker container named ppocr and map the current directory to the /paddle directory of the container

319
# If using CPU, use docker instead of nvidia-docker to create docker
qq_25193841's avatar
qq_25193841 已提交
320
sudo docker run --name ppocr -v $PWD:/paddle --network=host -it  paddlepaddle/paddle:latest-dev-cuda10.1-cudnn7-gcc82  /bin/bash
L
LDOUBLEV 已提交
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339

# If using GPU, use nvidia-docker to create docker
sudo nvidia-docker run --name ppocr -v $PWD:/paddle --shm-size=64G --network=host -it paddlepaddle/paddle:latest-dev-cuda10.1-cudnn7-gcc82 /bin/bash

```
You can also visit [DockerHub](https://hub.docker.com/r/paddlepaddle/paddle/tags/) to get the image that fits your machine.

```
# ctrl+P+Q to exit docker, to re-enter docker using the following command:
sudo docker container exec -it ppocr /bin/bash
```

The default python3 version in the docker environment is python3.5. Python3.7 is recommended to run PaddleOCR. When executing python commands, you can use python3.7 instead of python3. As follows, enter the python3.7 command and press Enter, you can see that the python3.7 version is used.
```
λ root@Linux /paddle python3.7
Python 3.7.0 (default, Aug 2 2021, 05:30:22)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
qq_25193841's avatar
qq_25193841 已提交
340 341 342 343 344 345 346 347 348
```

<a name="2"></a>

## 2. Install PaddlePaddle 2.0

- If you have cuda9 or cuda10 installed on your machine, please run the following command to install

```bash
L
fix_doc  
LDOUBLEV 已提交
349
# use python3.7 instead of python3 in docker
qq_25193841's avatar
qq_25193841 已提交
350 351 352 353 354 355
python3 -m pip install paddlepaddle-gpu -i https://mirror.baidu.com/pypi/simple
```

- If you only have cpu on your machine, please run the following command to install

```bash
L
fix_doc  
LDOUBLEV 已提交
356
# use python3.7 instead of python3 in docker
qq_25193841's avatar
qq_25193841 已提交
357 358 359 360 361
python3 -m pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple
```

For more software version requirements, please refer to the instructions in [Installation Document](https://www.paddlepaddle.org.cn/install/quick) for operation.

L
LDOUBLEV 已提交
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390

## 3. Install PaddleOCR Dependencies

Download PaddleOCR code.
```
# Recommend
git clone https://github.com/PaddlePaddle/PaddleOCR

# If you cannot pull successfully due to network problems, you can also choose to use the code hosting on the cloud:

git clone https://gitee.com/paddlepaddle/PaddleOCR

# Note: The cloud-hosting code may not be able to synchronize the update with this GitHub project in real time. There might be a delay of 3-5 days. Please give priority to the recommended method.
```

Install third-party libraries
```
cd PaddleOCR
pip3 install -r requirements.txt
# use pip3.7 instead of pip3 in docker
# pip3.7 install -r requirements.txt

```

If you getting this error OSError: [WinError 126] The specified module could not be found when you install shapely on windows.

Please try to download Shapely whl file using [http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely](http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely).

Reference: [Solve shapely installation on windows](https://stackoverflow.com/questions/44398265/install-shapely-oserror-winerror-126-the-specified-module-could-not-be-found)