Search code examples
pythonnumpygoogle-nativeclientppapi

How do I use the Python modules in webports/naclports with the Python interpreter Chrome app?


Webports has projects in the ports directory for Python and several Python modules, including NumPy. The "python" port compiles a Chrome app that runs the Python interpreter in a console window. I'd like to be able to use modules that include native code, like NumPy, in that interpreter.

Here's what I've tried:

  • make numpy followed by make python (in hopes that the Python build process sees that I've already built NumPy and includes it), which doesn't seem to change anything
  • Building the python-static package, which fails with a gigantic error message that ends with libppapi_simple_cpp.a: error: undefined reference to 'PSUserMainGet'
  • Copying out/build/numpy/numpy-1.8.0/numpy/ into the site-packages folder in pydata.tar in the Python app. import numpy fails with an error message telling me not to import NumPy from its source directory.
  • Copying out/build/numpy/numpy-1.8.0/build/lib.linux-x86_64-2.7/numpy/ (which appears to have compiled .so files in it) into the site-packages folder in pydata.tar. import numpy fails with this traceback:

    >>> import numpy
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/lib/python2.7/site-packages/numpy/__init__.py", line 153, in <module>
        from . import add_newdocs
      File "/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
        from numpy.lib import add_newdoc
      File "/lib/python2.7/site-packages/numpy/lib/__init__.py", line 8, in <module>
        from .type_check import *
      File "/lib/python2.7/site-packages/numpy/lib/type_check.py", line 11, in <module>
        import numpy.core.numeric as _nx
      File "/lib/python2.7/site-packages/numpy/core/__init__.py", line 6, in <module>
        from . import multiarray
    ImportError: cannot import name multiarray
    

I'm using the PNaCL toolchain version pepper_47 inside a Docker container to build the packages, and I'm running the Python app on Chrome 47.0.2526.106 (64-bit) on Xubuntu.


Solution

  • The raw python port doesn't catch it, but the numpy port was designed to be used with the python-static port, which will build using the modules that have previously been built. This will then assemble a unified static library that will be linked into the .pexe for python. You shouldn't need to copy any module components by hand.