Multiple Interpreters?

Andrew Bell andrew.bell.ia at gmail.com
Fri Jul 26 13:28:06 EDT 2019


Hi,

I'm trying to understand what might be going on with loading one Python
interpreter on top of a second.  I'm running on OSX with a conda python
installation.  I understand that python is now statically linked on conda.

I'm running python, which invokes an extension module.  This extension
module calls some C++ code that is trying to start a second interpreter --
it loads a shared object that's linked against libpython.dylib.  When I try
to initialize python (Py_Initialize) in the shared object loaded by the
extension module, it fails (see below).  I'm not mixing anything from the
original python invocation to the one I'm trying run and I'm sure that
Py_Initialize in the shared library invocation are from libpython.dylib,
rather than from the python interpreter (python3).  Is there some reason
why I can't run a second interpreter using libpython.dylib when my process
is already running python3?

(I know that I can solve this by not linking libpython.dylib and deferring
symbol resolution to runtime, which will force resolution to symbols in
python3, but I don't know at build time if I'm using a statically-linked
interpreter or not.  I'd like to understand why this fails when I'm not
sharing context with the original interpreter.)

Fatal Python error: initsite: Failed to import the site module
Traceback (most recent call last):
  File "/Users/acbell/miniconda3/envs/pdal/lib/python3.7/site.py", line
168, in addpackage
    exec(line)
  File "<string>", line 1, in <module>
  File
"/Users/acbell/miniconda3/envs/pdal/lib/python3.7/importlib/util.py", line
14, in <module>
    from contextlib import contextmanager
  File "/Users/acbell/miniconda3/envs/pdal/lib/python3.7/contextlib.py",
line 5, in <module>
    from collections import deque
  File
"/Users/acbell/miniconda3/envs/pdal/lib/python3.7/collections/__init__.py",
line 24, in <module>
    import heapq as _heapq
  File "/Users/acbell/miniconda3/envs/pdal/lib/python3.7/heapq.py", line
587, in <module>
    from _heapq import *

Thanks,

-- 
Andrew Bell
andrew.bell.ia at gmail.com



More information about the Python-list mailing list