RAGflow 以源代码启动服务 pyicu模块报错解决方案

原来教程的README文件

## 以源代码启动服务

1. 安装 uv。如已经安装,可跳过本步骤:

### 解释
- Python.h 是 Python 的开发头文件,只有安装了 Python 的开发环境(开发包)才会有。
- 在 Linux/WSL 环境下,通常需要安装 python3-dev 或 python3.10-dev 这样的包,才能提供 Python.h 。
- 没有这个头文件,任何需要 C/C++ 扩展编译的 Python 包(如 pyicu)都无法安装成功。
### 解决方法
请在你的 Linux/WSL 终端执行以下命令安装 Python 开发包:

```bash
sudo apt-get update
sudo apt-get install python3.10-dev
 ```
```

如果你用的是其他 Python 版本,比如 3.11,请将命令中的 python3.10-dev 替换为对应版本的开发包。

安装完成后,再重新运行你的 uv sync --python 3.10 --all-extras 命令即可。

2. 下载源代码并安装 Python 依赖:

   ```bash

   git clone https://github.com/infiniflow/ragflow.git

   cd ragflow/

   uv sync --python 3.10 --all-extras # install RAGFlow dependent python modules

   ```

但是用UV安装所需要的包的时候,pyicu包会因为 你的系统缺少 pyicu 编译所需的 ICU 库开发文件和工具。

安装 libicu-dev 和 pkg-config 后即可解决。

运行以下代码

sudo apt-get update
sudo apt-get install libicu-dev pkg-config

报错显示:

shuozhang@Shawn:/mnt/d/Project-41-1$ uv sync --python 3.10 --all-extras
Resolved 380 packages in 5ms
      Built flagembedding==1.2.10
      Built peewee==3.17.1
      Built volcengine==1.0.146
      Built jsonpath==0.82.2
      Built html2text==2024.2.26
      Built thrift==0.20.0
      Built pyexecjs==1.5.1
      Built bibtexparser==1.4.3
      Built free-proxy==1.1.3
      Built sgmllib3k==1.0.0
      Built warc3-wet-clueweb09==0.2.5
      Built cbor==1.0.0
  × Failed to build `pyicu==2.15`
  ├─▶ The build backend returned an error
  ╰─▶ Call to `setuptools.build_meta.build_wheel` failed (exit status: 1)

      [stdout]
      (running 'icu-config --version')
      (running 'pkg-config --modversion icu-i18n')

      Building PyICU 2.15 for ICU 74.2 (max ICU major version supported: 77)

      (running 'icu-config --cxxflags --cppflags')
      Could not configure CFLAGS with icu-config
      (running 'pkg-config --cflags icu-i18n')
      (running 'icu-config --ldflags')
      Could not configure LFLAGS with icu-config
      (running 'pkg-config --libs icu-i18n')
      Adding LFLAGS="-licui18n -licuuc -licudata" from /usr/bin/pkg-config
      running bdist_wheel
      running build
      running build_py
      copying py/icu/__init__.py -> build/lib.linux-x86_64-cpython-310/icu
      running build_ext
      building 'icu._icu_' extension
      x86_64-linux-gnu-g++ -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall
      -g -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fstack-protector-strong
      -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -g -fwrapv -O2     
      -fPIC -I/home/shuozhang/.cache/uv/builds-v0/.tmpUrts1A/include -I/usr/include/python3.10     
      -c _icu_.cpp -o build/temp.linux-x86_64-cpython-310/_icu_.o -std=c++17 -DPYICU_VER=\"2.15\"  
      -DPYICU_ICU_MAX_VER=\"77\"

      [stderr]
      :56: DeprecationWarning: Use shutil.which instead of find_executable
      /home/shuozhang/.cache/uv/builds-v0/.tmpUrts1A/lib/python3.10/site-packages/setuptools/_distutils/dist.py:289:
      UserWarning: Unknown distribution option: 'test_suite'
        warnings.warn(msg)
      /home/shuozhang/.cache/uv/builds-v0/.tmpUrts1A/lib/python3.10/site-packages/setuptools/_distutils/dist.py:289:
      UserWarning: Unknown distribution option: 'tests_require'
        warnings.warn(msg)
      /home/shuozhang/.cache/uv/builds-v0/.tmpUrts1A/lib/python3.10/site-packages/setuptools/dist.py:759:
      SetuptoolsDeprecationWarning: License classifiers are deprecated.
      !!

              ********************************************************************************     
              Please consider removing the following classifiers in favor of a SPDX license        
      expression:

              License :: OSI Approved

              See https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license    
      for details.
              ********************************************************************************     

      !!
        self._finalize_license_expression()
      _icu_.cpp:24:10: fatal error: Python.h: No such file or directory
         24 | #include 
            |          ^~~~~~~~~~
      compilation terminated.
      error: command '/usr/bin/x86_64-linux-gnu-g++' failed with exit code 1

      hint: This error likely indicates that you need to install a library that provides
      "Python.h" for `[email protected]`
  help: `pyicu` (v2.15) was included because `ragflow` (v0.17.2) depends on `pyicu`

报错信息显示在安装 pyicu 这个 Python 包时,编译过程中找不到 Python.h 文件,导致构建失败。

### 解释
- Python.h 是 Python 的开发头文件,只有安装了 Python 的开发环境(开发包)才会有。
- 在 Linux/WSL 环境下,通常需要安装 python3-dev 或 python3.10-dev 这样的包,才能提供 Python.h 。
- 没有这个头文件,任何需要 C/C++ 扩展编译的 Python 包(如 pyicu)都无法安装成功。
### 解决方法
请在你的 Linux/WSL 终端执行以下命令安装 Python 开发包:

```bash
sudo apt-get update
sudo apt-get install python3.10-dev
 ```


```

如果你用的是其他 Python 版本,比如 3.11,请将命令中的 python3.10-dev 替换为对应版本的开发包。

安装完成后,再重新运行你的

 uv sync --python 3.10 --all-extras 

命令即可。

你可能感兴趣的:(python,RAGFLOW)