安装 python 的 Postal (Address Parser) 包时出现问题

Posted

技术标签:

【中文标题】安装 python 的 Postal (Address Parser) 包时出现问题【英文标题】:Issue while installing Postal (Address Parser ) package of python 【发布时间】:2020-04-30 23:38:01 【问题描述】:

我正在尝试使用

安装邮政包裹
pip install postal

我正在按照链接中提到的步骤进行操作 https://github.com/openvenues/libpostal#installation-windows

我已安装 Visual Studio 2019 C++ Build Tools、MSYS2 并执行了该步骤

git clone https://github.com/openvenues/libpostal
cd libpostal
cp -rf windows/* ./
./bootstrap.sh
./configure --datadir=[...some dir with a few GB of space...]
make -j4
make install

我仍然无法使用pip install postal 安装邮包

安装邮包时获取以下日志。

(base) C:\Users\Praveen>pip install postal
Collecting postal
  Using cached https://files.pythonhosted.org/packages/56/f7/69ca5d374077e23aa9a51ecd4031222ca9dfb7d19c95d7691f024e2e27ef/postal-1.1.8.tar.gz
Requirement already satisfied: six in c:\programdata\anaconda3\lib\site-packages (from postal) (1.12.0)
Building wheels for collected packages: postal
  Building wheel for postal (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: 'C:\ProgramData\Anaconda3\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Praveen\\AppData\\Local\\Temp\\pip-install-9sens8xe\\postal\\setup.py'"'"'; __file__='"'"'C:\\Users\\Praveen\\AppData\\Local\\Temp\\pip-install-9sens8xe\\postal\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\Praveen\AppData\Local\Temp\pip-wheel-e6vpt_0y' --python-tag cp37
       cwd: C:\Users\Praveen\AppData\Local\Temp\pip-install-9sens8xe\postal\
  Complete output (35 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build\lib.win-amd64-3.7
  creating build\lib.win-amd64-3.7\postal
  copying postal\dedupe.py -> build\lib.win-amd64-3.7\postal
  copying postal\expand.py -> build\lib.win-amd64-3.7\postal
  copying postal\near_dupe.py -> build\lib.win-amd64-3.7\postal
  copying postal\normalize.py -> build\lib.win-amd64-3.7\postal
  copying postal\parser.py -> build\lib.win-amd64-3.7\postal
  copying postal\tokenize.py -> build\lib.win-amd64-3.7\postal
  copying postal\token_types.py -> build\lib.win-amd64-3.7\postal
  copying postal\__init__.py -> build\lib.win-amd64-3.7\postal
  creating build\lib.win-amd64-3.7\postal\tests
  copying postal\tests\test_expand.py -> build\lib.win-amd64-3.7\postal\tests
  copying postal\tests\test_parser.py -> build\lib.win-amd64-3.7\postal\tests
  copying postal\tests\_test_near_dupes.py -> build\lib.win-amd64-3.7\postal\tests
  copying postal\tests\__init__.py -> build\lib.win-amd64-3.7\postal\tests
  creating build\lib.win-amd64-3.7\postal\utils
  copying postal\utils\encoding.py -> build\lib.win-amd64-3.7\postal\utils
  copying postal\utils\enum.py -> build\lib.win-amd64-3.7\postal\utils
  copying postal\utils\omitted.py -> build\lib.win-amd64-3.7\postal\utils
  copying postal\utils\__init__.py -> build\lib.win-amd64-3.7\postal\utils
  copying postal\pyutils.h -> build\lib.win-amd64-3.7\postal
  running build_ext
  building 'postal._expand' extension
  creating build\temp.win-amd64-3.7
  creating build\temp.win-amd64-3.7\Release
  creating build\temp.win-amd64-3.7\Release\postal
  C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.20.27508\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -I/usr/local/include -IC:\ProgramData\Anaconda3\include -IC:\ProgramData\Anaconda3\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.20.27508\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt" /Tcpostal/pyexpand.c /Fobuild\temp.win-amd64-3.7\Release\postal/pyexpand.obj -std=c99
  cl : Command line warning D9002 : ignoring unknown option '-std=c99'
  pyexpand.c
  postal/pyexpand.c(2): fatal error C1083: Cannot open include file: 'libpostal/libpostal.h': No such file or directory
  error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.20.27508\\bin\\HostX86\\x64\\cl.exe' failed with exit status 2
  ----------------------------------------
  ERROR: Failed building wheel for postal
  Running setup.py clean for postal
Failed to build postal
Installing collected packages: postal
  Running setup.py install for postal ... error
    ERROR: Command errored out with exit status 1:
     command: 'C:\ProgramData\Anaconda3\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Praveen\\AppData\\Local\\Temp\\pip-install-9sens8xe\\postal\\setup.py'"'"'; __file__='"'"'C:\\Users\\Praveen\\AppData\\Local\\Temp\\pip-install-9sens8xe\\postal\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\Praveen\AppData\Local\Temp\pip-record-k92kr5uk\install-record.txt' --single-version-externally-managed --compile
         cwd: C:\Users\Praveen\AppData\Local\Temp\pip-install-9sens8xe\postal\
    Complete output (35 lines):
    running install
    running build
    running build_py
    creating build
    creating build\lib.win-amd64-3.7
    creating build\lib.win-amd64-3.7\postal
    copying postal\dedupe.py -> build\lib.win-amd64-3.7\postal
    copying postal\expand.py -> build\lib.win-amd64-3.7\postal
    copying postal\near_dupe.py -> build\lib.win-amd64-3.7\postal
    copying postal\normalize.py -> build\lib.win-amd64-3.7\postal
    copying postal\parser.py -> build\lib.win-amd64-3.7\postal
    copying postal\tokenize.py -> build\lib.win-amd64-3.7\postal
    copying postal\token_types.py -> build\lib.win-amd64-3.7\postal
    copying postal\__init__.py -> build\lib.win-amd64-3.7\postal
    creating build\lib.win-amd64-3.7\postal\tests
    copying postal\tests\test_expand.py -> build\lib.win-amd64-3.7\postal\tests
    copying postal\tests\test_parser.py -> build\lib.win-amd64-3.7\postal\tests
    copying postal\tests\_test_near_dupes.py -> build\lib.win-amd64-3.7\postal\tests
    copying postal\tests\__init__.py -> build\lib.win-amd64-3.7\postal\tests
    creating build\lib.win-amd64-3.7\postal\utils
    copying postal\utils\encoding.py -> build\lib.win-amd64-3.7\postal\utils
    copying postal\utils\enum.py -> build\lib.win-amd64-3.7\postal\utils
    copying postal\utils\omitted.py -> build\lib.win-amd64-3.7\postal\utils
    copying postal\utils\__init__.py -> build\lib.win-amd64-3.7\postal\utils
    copying postal\pyutils.h -> build\lib.win-amd64-3.7\postal
    running build_ext
    building 'postal._expand' extension
    creating build\temp.win-amd64-3.7
    creating build\temp.win-amd64-3.7\Release
    creating build\temp.win-amd64-3.7\Release\postal
    C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.20.27508\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -I/usr/local/include -IC:\ProgramData\Anaconda3\include -IC:\ProgramData\Anaconda3\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.20.27508\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt" /Tcpostal/pyexpand.c /Fobuild\temp.win-amd64-3.7\Release\postal/pyexpand.obj -std=c99
    cl : Command line warning D9002 : ignoring unknown option '-std=c99'
    pyexpand.c
    postal/pyexpand.c(2): fatal error C1083: Cannot open include file: 'libpostal/libpostal.h': No such file or directory
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.20.27508\\bin\\HostX86\\x64\\cl.exe' failed with exit status 2
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'C:\ProgramData\Anaconda3\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Praveen\\AppData\\Local\\Temp\\pip-install-9sens8xe\\postal\\setup.py'"'"'; __file__='"'"'C:\\Users\\Praveen\\AppData\\Local\\Temp\\pip-install-9sens8xe\\postal\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\Praveen\AppData\Local\Temp\pip-record-k92kr5uk\install-record.txt' --single-version-externally-managed --compile Check the logs for full command output.

【问题讨论】:

【参考方案1】:

尝试以下解决方案。我在 WSL 中运行它。

变化

    在所有命令之前导航到 cd~ 目录。 在 make 之前使用“sudo”。
cd~
git clone https://github.com/openvenues/libpostal
cd libpostal
./bootstrap.sh
./configure
sudo make
sudo make install

然后运行 pip install postal

在导入和运行 postal 库之前,还要 pip install nose

【讨论】:

【参考方案2】:

大多数时候,libpostal 在 windows python 绑定中失败,所以我有一个新的 python 包,捆绑了 libpostal 并使用 python 包,它可以使用。

这是一个名为pypostalwin的包

按照自述文件的说明,享受从 python 中使用 libpostal 的乐趣

【讨论】:

以上是关于安装 python 的 Postal (Address Parser) 包时出现问题的主要内容,如果未能解决你的问题,请参考以下文章

MVC4 Postal - 通过 UserId 访问用户电子邮件地址搜索

British postal system to launch parcel postboxes

无法从 Postal Pincode API 获取数据

findOrFail Laravel 5 特定领域的功能

使用 Boost 库从 C++ 中的 JSON 检索内容

influxd安装