1

我想将我的 python 库转换为可以在浏览器中运行的 Javascript。到目前为止,我尝试了以下方法但没有成功。

cython --embed -a saidpythonlibrary.pyx
eemcc -isystem /Users/username/anaconda/envs/my_env/include/python2.7 saidpythonlibrary.c -o saidpythonlibrary.js

但是 eemcc 抱怨以下内容:

warning: unresolved symbol: PySys_SetArgv
warning: unresolved symbol: Py_Initialize
warning: unresolved symbol: PyNumber_Absolute
warning: unresolved symbol: PyList_New
warning: unresolved symbol: PyObject_IsTrue
warning: unresolved symbol: PyList_Append
warning: unresolved symbol: PyFrame_New
warning: unresolved symbol: Py_Finalize
warning: unresolved symbol: PyNumber_FloorDivide
warning: unresolved symbol: PyFloat_FromString
warning: unresolved symbol: PyUnicodeUCS2_DecodeUTF8
warning: unresolved symbol: PyObject_GetItem
warning: unresolved symbol: PyNumber_Remainder
warning: unresolved symbol: PyDict_SetItem
warning: unresolved symbol: Py_FlushLine
warning: unresolved symbol: PySequence_Tuple
warning: unresolved symbol: PyErr_Print
warning: unresolved symbol: PyObject_Size
warning: unresolved symbol: PyErr_ExceptionMatches
warning: unresolved symbol: PyObject_Call
warning: unresolved symbol: PyObject_GetIter
warning: unresolved symbol: PyNumber_Index
warning: unresolved symbol: PyString_Size
warning: unresolved symbol: PyNumber_Int
warning: unresolved symbol: PyObject_RichCompare
warning: unresolved symbol: PyInt_FromSsize_t
warning: unresolved symbol: PyDict_GetItem
warning: unresolved symbol: PyErr_Occurred
warning: unresolved symbol: PyLong_AsSsize_t
warning: unresolved symbol: PyModule_GetDict
warning: unresolved symbol: PyFloat_FromDouble
warning: unresolved symbol: PyLong_FromLong
warning: unresolved symbol: PyUnicodeUCS2_Compare
warning: unresolved symbol: PyDict_Size
warning: unresolved symbol: PyString_AsString
warning: unresolved symbol: PyNumber_InPlaceDivide
warning: unresolved symbol: PyErr_WarnEx
warning: unresolved symbol: PyNumber_InPlaceSubtract
warning: unresolved symbol: PyOS_snprintf
warning: unresolved symbol: _PyString_Join
warning: unresolved symbol: PyEval_EvalCodeEx
warning: unresolved symbol: PyNumber_InPlaceRemainder
warning: unresolved symbol: PyNumber_Subtract
warning: unresolved symbol: PyInt_AsSsize_t
warning: unresolved symbol: _PyString_Eq
warning: unresolved symbol: PyErr_Clear
warning: unresolved symbol: PyObject_SetAttrString
warning: unresolved symbol: PyLong_AsDouble
warning: unresolved symbol: PyFile_SoftSpace
warning: unresolved symbol: PyCFunction_NewEx
warning: unresolved symbol: _Py_CheckRecursiveCall
warning: unresolved symbol: PyNumber_Add
warning: unresolved symbol: PyString_FromString
warning: unresolved symbol: PyErr_SetString
warning: unresolved symbol: PyEval_EvalFrameEx
warning: unresolved symbol: PyCode_New
warning: unresolved symbol: PySys_GetObject
warning: unresolved symbol: PyErr_NormalizeException
warning: unresolved symbol: PyErr_Format
warning: unresolved symbol: PyNumber_InPlaceAdd
warning: unresolved symbol: Py_InitModule4_64
warning: unresolved symbol: PyTuple_Pack
warning: unresolved symbol: PyString_FromStringAndSize
warning: unresolved symbol: PyErr_SetObject
warning: unresolved symbol: PyNumber_InPlaceFloorDivide
warning: unresolved symbol: PyString_InternFromString
warning: unresolved symbol: PyType_IsSubtype
warning: unresolved symbol: PyTuple_New
warning: unresolved symbol: PyNumber_Multiply
warning: unresolved symbol: Py_GetVersion
warning: unresolved symbol: PyMem_Realloc
warning: unresolved symbol: PyDict_Next
warning: unresolved symbol: Py_SetProgramName
warning: unresolved symbol: PyMem_Malloc
warning: unresolved symbol: PyDict_New
warning: unresolved symbol: PyObject_GetAttr
warning: unresolved symbol: PyNumber_Divide
warning: unresolved symbol: PyNumber_Power
warning: unresolved symbol: PyFile_WriteObject
warning: unresolved symbol: PyInt_FromLong
warning: unresolved symbol: PyObject_SetItem
warning: unresolved symbol: PyLong_FromLongLong
warning: unresolved symbol: PyImport_AddModule
warning: unresolved symbol: PyErr_GivenExceptionMatches
warning: unresolved symbol: PyObject_CallFunctionObjArgs
warning: unresolved symbol: PyTraceBack_Here
warning: unresolved symbol: PyUnicodeUCS2_FromStringAndSize
warning: unresolved symbol: PyString_FromFormat
warning: unresolved symbol: PyFile_WriteString
warning: unresolved symbol: PyCFunction_Type
warning: unresolved symbol: PyExc_AssertionError
warning: unresolved symbol: PyExc_AttributeError
warning: unresolved symbol: PyExc_BaseException
warning: unresolved symbol: PyExc_Exception
warning: unresolved symbol: PyExc_ImportError
warning: unresolved symbol: PyExc_NameError
warning: unresolved symbol: PyExc_OverflowError
warning: unresolved symbol: PyExc_RuntimeError
warning: unresolved symbol: PyExc_StopIteration
warning: unresolved symbol: PyExc_SystemError
warning: unresolved symbol: PyExc_TypeError
warning: unresolved symbol: PyExc_UnboundLocalError
warning: unresolved symbol: PyExc_ValueError
warning: unresolved symbol: PyExc_ZeroDivisionError
warning: unresolved symbol: PyFloat_Type
warning: unresolved symbol: PyFunction_Type
warning: unresolved symbol: PyInt_Type
warning: unresolved symbol: PyList_Type
warning: unresolved symbol: PyLong_Type
warning: unresolved symbol: PyMethod_Type
warning: unresolved symbol: PyString_Type
warning: unresolved symbol: PyTraceBack_Type
warning: unresolved symbol: PyTuple_Type
warning: unresolved symbol: PyUnicode_Type
warning: unresolved symbol: Py_OptimizeFlag
warning: unresolved symbol: _PyThreadState_Current
warning: unresolved symbol: _Py_CheckRecursionLimit
warning: unresolved symbol: _Py_NoneStruct
warning: unresolved symbol: _Py_TrueStruct
warning: unresolved symbol: _Py_ZeroStruct

这些函数在 c 输入中缺失,在 JS 输出中,它们作为未实现的存根函数存在,例如

 function _Py_SetProgramName() {
  Module['printErr']('missing function: Py_SetProgramName'); abort(-1);
  }

正如预期的那样,当我尝试通过节点运行 JS 时,它会出错:

missing function: Py_SetProgramName
-1
-1
exception thrown: abort(-1) at Error
    at jsStackTrace (/Users/username/code/saidpythonlibrary/saidpythonlibrary/saidpythonlibrary.js:1121:13)
    at stackTrace (/Users/username/code/saidpythonlibrary/saidpythonlibrary/saidpythonlibrary.js:1138:12)
    at abort (/Users/username/code/saidpythonlibrary/saidpythonlibrary/saidpythonlibrary.js:80725:44)
    at _Py_SetProgramName (/Users/username/code/saidpythonlibrary/saidpythonlibrary/saidpythonlibrary.js:2022:62)
    at _main (/Users/username/code/saidpythonlibrary/saidpythonlibrary/saidpythonlibrary.js:6736:3)
    at Object.asm._main (/Users/username/code/saidpythonlibrary/saidpythonlibrary/saidpythonlibrary.js:80371:19)
4

0 回答 0