objective c - Embedded Python 3 not creating .pyc files when using importlib -


i'm trying embed python 3 interpreter in objective c cocoa app on mac, following instructions in this answer (which extends this article) , building python , pyobjc hand.

i'd able run python code plugins. don't want rely on stock apple python (v2.7). have of working can't seem reliably load plugin scripts. looks embedded python interpreter unable create __pycache__/*.pyc files. may symptom, or cause. if import plugin file manually python3 repl (via import or imp or importlib modules) .pyc generated , plugin loads correctly. if don't manually .pyc not created , receive valueerror "unmarshallable object".

i've tried loosening permissions on script directory no avail. cache_tag looks ok, both repl , within bouncer script:

>>> sys.implementation.cache_tag 'cpython-35' 

py_compile raises cocoa exception if try , compile plugin file manually (i'm still digging that).

i'm using following:

  • os x 10.11.5 (el capitan)
  • xcode 7.2.1
  • python v3.5.2
  • pyobjc v3.11

i had make couple of necessary tweaks process outlined in linked answer:

compiling python 3 required homebrew versions of openssl , zlib, , appropriate ldflags , cppflags:

export cppflags="-i$(brew --prefix openssl)/include -i$(brew --prefix zlib)/include" export ldflags="-l$(brew --prefix openssl)/lib -l$(brew --prefix zlib)/lib" 

i ensure pip installed ok when configuring python build:

./configure --prefix="/path/to/python/devbuild/python3.5.2" --with-ensurepip=install 

there fork of original article source (which uses stock python2) works fine here, suspect i'm not far off mark. idea i've missed? need sign, or otherwise give permission to, embedded python? there complilation/configuration options i've neglected set?

tia

typical. it's last thing try, isn't it? adding directory containing plugin scripts sys.path seems trick, although i'm not sure why importlib needs (i thought point allow circumvent normal import mechanism). perhaps it's way default importlib.machinery.sourcefileloader implemented?

something like:

sys.path.append(os.path.abspath("/path/to/plugin/scripts")) 

makes "unmarshallable object" problem go away. cache directory , .pyc files created correctly.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -