首页 > 解决方案 > PythonKit 错误“找不到 Python 库。使用 Python 库的路径设置 PYTHON_LIBRARY 环境变量”

问题描述

我正在使用带有 XCode 的 PythonKit 从 swift 代码中调用 spaCy API。从 Home-brew 安装 PythonKit,将其导入我的项目并构建良好;但是,在运行时我收到了错误:

Python library not found. Set the PYTHON_LIBRARY environment variable with the path to a Python library.

所以我编译了 PythonTools(在 PythonKit 目录中,运行swift package generate-xcodeproj并打开 PythonKit.xcodeproj 文件)来查看它会找到哪些 Python 库路径:

/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python37.zip
/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7
/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload
/Users/fernandabrum/Library/Python/3.7/lib/python/site-packages
/usr/local/lib/python3.7/site-packages

如果我的系统中有 Python 库,为什么我会收到找不到 Python 库的错误?我究竟做错了什么?

OBS.:我还尝试使用export PYTHON_LIBRARY=上面找到的路径设置 PYTHON_LIBRARY,但没有成功。

提前致谢!

标签: pythoniosxcodespacy

解决方案


在 Signing and Capabilities 下的“Hardened Runtime”中:选中“Disable Library Validation” 在此处查看答案:I can't import Python modules in Xcode 11 using PythonKit


推荐阅读