Windows下安装lmdb报错

尝试在Windows安装用paddleocr时,发现在环境配置中安装lmdb的过程中会报错:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 报错提示
Collecting lmdb
Using cached lmdb-1.4.1.tar.gz (881 kB)
Preparing metadata (setup.py) ... done
Building wheels for collected packages: lmdb
Building wheel for lmdb (setup.py) ... error
error: subprocess-exited-with-error

× python setup.py bdist_wheel did not run successfully.
exit code: 1
╰─> [15 lines of output]
py-lmdb: Using bundled liblmdb with py-lmdb patches; override with LMDB_FORCE_SYSTEM=1 or LMDB_PURE=1.
py-lmdb: Using CPython extension; override with LMDB_FORCE_CFFI=1.
running bdist_wheel
running build
running build_py
creating build\lib.win-amd64-cpython-312
creating build\lib.win-amd64-cpython-312\lmdb
copying lmdb\cffi.py -> build\lib.win-amd64-cpython-312\lmdb
copying lmdb\tool.py -> build\lib.win-amd64-cpython-312\lmdb
copying lmdb\_config.py -> build\lib.win-amd64-cpython-312\lmdb
copying lmdb\__init__.py -> build\lib.win-amd64-cpython-312\lmdb
copying lmdb\__main__.py -> build\lib.win-amd64-cpython-312\lmdb
running build_ext
building 'cpython' extension
error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for lmdb
Running setup.py clean for lmdb
Failed to build lmdb
ERROR: Could not build wheels for lmdb, which is required to install pyproject.toml-based projects

故在这里记录下解决问题的方法:

  • 下载Visual CPP build tools,下载并运行vs_BuildTools.exe。
  • 按照提示安装Visual Studio Installer,安装“Visual Studio生成工具”。
  • 安装完成后再点击“Visual Studio生成工具”的修改按钮,勾选“使用C++的桌面开发”,进行修改

此时即可正常安装lmdb。