Hi.
I'm experimenting with @pvieito's great looking PythonKit. I'm having a weird dlopen
/search path issue.
I'm wondering if anyone can advise?
Problem
Following the project README I have a very simple hello world setup that imports PythonKit, sets sys.path
to find my local script, imports that, and calls a function that prints a Hello, World!.
Thus far, all great. Out of the box, PythonKit is finding Python 2.7, so (again following the README) I try setting the PYTHON_VERSION
and PYTHON_LIBRARY
environment variables. (I also set PYTHON_LOADER_LOGGING
for good measure.)
The issue is PYTHON_LIBRARY
seems correct — it reports as loading correctly — but Python 2.7 is still being loaded.
This is the sample code from the README:
let sys = Python.import("sys")
print("Python \(sys.version_info.major).\(sys.version_info.minor)")
print("Python Version: \(sys.version)")
print("Python Encoding: \(sys.getdefaultencoding().upper())")
Which (with PYTHON_LIBRARY
set) outputs:
Loading symbol 'Py_Initialize' from the Python library...
Trying to load library at '/opt/boxen/homebrew/Cellar/python@3.8/3.8.7/Frameworks/Python.framework/Python'...
Library at '/opt/boxen/homebrew/Cellar/python@3.8/3.8.7/Frameworks/Python.framework/Python' was sucessfully loaded.
Loading symbol 'PyEval_GetBuiltins' from the Python library...
Loading symbol 'Py_IncRef' from the Python library...
Loading symbol 'PyRun_SimpleString' from the Python library...
Loading symbol 'PyImport_ImportModule' from the Python library...
Loading symbol 'PyObject_GetAttrString' from the Python library...
Loading symbol 'Py_DecRef' from the Python library...
Loaded legacy Python library, using legacy symbols...
Loading symbol 'PyString_FromStringAndSize' from the Python library...
Loading symbol 'PyObject_GetItem' from the Python library...
Loading symbol 'PyErr_Occurred' from the Python library...
Loading symbol 'PyTuple_New' from the Python library...
Loading symbol 'PyTuple_SetItem' from the Python library...
Loading symbol 'PyObject_CallObject' from the Python library...
Loading symbol 'PyString_AsString' from the Python library...
Python 2.7
Python Version: 2.7.16 (default, Jan 22 2021, 05:09:26)
[GCC Apple LLVM 12.0.5 (clang-1205.0.19.9) [+internal-os, ptrauth-isa=deploymen
Python Encoding: ASCII
With the Library at <PATH> was sucessfully loaded.
, which is the 3rd line of the output above , I'm expecting Python 3.8, but 2.7 is in fact what we get.
With a test script such as:
print("Hello, world! (From Python 💃)")
... we get a crash, without declaring the file encoding — Ah, yes, definitely Python 2…
I'm not quite sure (yet) how to get the planets aligned here. How can I get PythonKit to pick up the right Python version? Is there something obvious I'm missing? (Quite likely.)
Many thanks if you're to advise! I know this sort of thing is difficult to comment on.
Kind Regards,
Carlton