PythonKit error "Python library not found. Set the PYTHON_LIBRARY environment variable with the path to a Python library"
Asked Answered
C

3

6

I'm using PythonKit with XCode to call spaCy API from swift code. Installed PythonKit from Home-brew, imported it in my project and it built well; however, at runtime I got the error:

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

So I compiled PythonTools (within PythonKit dir, run swift package generate-xcodeproj and open PythonKit.xcodeproj file ) to see which paths of Python library it would find:

/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

If Python libraries are in my system, why I get an error of Python library not found? What am I doing wrong?

OBS.:I also tried to set PYTHON_LIBRARY with export PYTHON_LIBRARY= and the paths found above, but unsuccessful.

Thanks in advance!

Counterpart answered 5/2, 2020 at 16:32 Comment(2)
Did you find any solution for this?Lotus
Also curious if you got this worked out. In my case I'm trying to load python 3.8 on Ubuntu. I've tried PythonLibrary.useVersion(3) and PythonLibrary.useLibrary(at: "/usr/bin/python3.8"), as well as the linuxbrew install, but nothing other than the /usr/bin/python (2.17) version works.Zygotene
Z
4

I finally solved this problem, in my case, by setting App Sandbox to NO in my app's .entitlements file. I also have Hardened Runtime and Enable App Sandbox set to NO in build settings, but those settings don't work without modifying the entitlements file... at least not in my case.

My understanding is that I can't distribute an app this way, so maybe kinda useless for some, but this is just a simple dev tool for testing some python code that will eventually be called from Vapor, so not a huge deal for me.

Zygotene answered 9/10, 2021 at 16:18 Comment(1)
It will stop you from sharing app to appstore. I have seen mutiple files on app store running python. How to run that on distributed app?Bruin
M
1

In "Hardened Runtime" under Signing and Capabilities: check "Disable Library Validation" See the answer here: I can't import Python modules in Xcode 11 using PythonKit

Microfilm answered 15/2, 2020 at 3:36 Comment(0)
D
0

It looks like the python library does not support iOS yet. It is working fine on OS X.

Decrescent answered 9/6, 2021 at 20:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.