Closed eldare closed 1 year ago
I believe the issue is your PythonKit configuration. The math module definitely exists, and can be used successfully (verified by both the Python-support-testbed app), and manual testing by adding import math
to a Briefcase test project.
From what you've described, the interpreter can't find your lib-dynload path. os
and pathlib
are backed by a os.py
and pathlib.py
respectively; math is a binary module in the lib-dynload
directory. PYTHONHOME
needs to point to a base folder that contains lib/python3.X
; and/or PYTHONPATH
needs to include the lib-dynload
folder. If nether of those things are true, then the interpreter won't be able to find the binary module to load at runtime.
@freakboy3742 Thank you for the reply. You're right lib-dynload
was missing from PYTHONPATH
. I've added it, and I'm getting a more specific error Contents/Resources/python-stdlib/lib-dynload/math.cpython-311-darwin.so' not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.)
I need to sign it with my TeamID.
I've looked though briefcase project, and found this. It worked :)
set -e
echo "Signed as $EXPANDED_CODE_SIGN_IDENTITY_NAME ($EXPANDED_CODE_SIGN_IDENTITY)"
find "$CODESIGNING_FOLDER_PATH/Contents/Resources/python-stdlib/lib-dynload" -name "*.so" -exec /usr/bin/codesign --force --sign "$EXPANDED_CODE_SIGN_IDENTITY" -o runtime --timestamp=none --preserve-metadata=identifier,entitlements,flags --generate-entitlement-der {} \;
Thank you for pointing me to the right direction 🙏
@eldare FWIW: We're not actively supporting other use cases external to Briefcase at present, but if someone were to write up a usage guide as a PR, I wouldn't reject the PR.
I understand. Thank you again :)
@freakboy3742 as suggested, I've submitted a PR with a detailed usage guide. https://github.com/beeware/Python-Apple-support/pull/171
Describe the bug
import math
throws the following error:Python exception: No module named 'math'
To Reproduce Steps to reproduce the behavior:
setenv("PYTHONHOME", "<python-stdlib location>", 1)
setenv("PYTHONPATH", "<python-stdlib location>", 1)
Py_Initialize()
Python.import("sys")
-> WorksPython.import("os")
-> WorksPython.import("pathlib")
-> WorksPython.import("math")
-> ExceptionExpected behavior It should be possible to
import math
.Screenshots
Environment:
Additional context I've tried to use
Python-3.10-macOS-support.b6
, only to the get the same exception.I tried to make sure the source of the issue is not coming from PythonKit. I used the local Python 3.11 on the mac (by removing the MacOS App's Sandbox + "Disable Library Validation"). It was able to import math with issues.
Thank you