0

I'm having issues trying to get cython working with the gcc compiler. I want to use the gcc compiler because I've heard it's harder to get your code from the executable using pyinstaller.

I'm on 64-bit Windows 10.

I have an application that is written in python 3.10.4. It is a command line application that goes against AWS, so there's no Windows calls in it.

I can produce the executable using pyinstaller and it works.

However, when I use the cython command to produce the .c module with a command like this:

cython -3 -o name.c name.py

That seems to work just fine or at least it doesn't generate errors.

Then I tried to create the executable and I've run into all sorts of problems that many others have run into on the internet, too.

I compile it with this command:

gcc -I (path)\Python310\include -L (path)\Python310\libs -lpython310 name.c -o name.exe

and I get this: name.c:220:41: warning: division by zero [-Wdiv-by-zero] 220 | enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) }; | ^ name.c:220:12: error: enumerator value for '__pyx_check_sizeof_voidp' is not an integer constant 220 | enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) }; | ^~~~~~~~~~~~~~~~~~~~~~~~

I've tried adding the -DMS_WIN64 option to the gcc command, but then it sends a bunch of errors regarding __imp_Py* and it complains about undefined reference to `WinMain'

I have no clue how to fix this. Can someone help me?

I'm using gcc version 12.1.0

Here are the __Imp_Py* errors for search purposes:

undefined reference to `__imp_PyType_IsSubtype' '__imp__Py_Dealloc' '__imp_PySequence_Contains' '__imp_PyList_Append' '__imp__PyType_Lookup' '__imp_PyExc_AttributeError' '__imp_PyErr_SetObject' '__imp_PyMethod_Type' '__imp_PyTuple_New' '__imp_PyDict_Size' '__imp__PyDict_GetItem_KnownHash' '__imp_PyNumber_Add' '__imp_PyUnicode_Type' '__imp_PyUnicode_Concat' '__imp__PyThreadState_UncheckedGet' '__imp__Py_NoneStruct' '__imp_PyDict_New' '__imp_PyDict_SetItem' '__imp_PyNumber_Subtract' '__imp_PyUnicode_Split' '__imp_PyNumber_Remainder' '__imp_PyUnicode_Format' '__imp_PyExc_Exception' '__imp_PyDict_Type' '__imp_PyObject_GetItem' '__imp_PyList_Type' '__imp_PyTuple_Type' '__imp_PyObject_GetIter' '__imp_PyErr_Occurred' '__imp_PyExc_StopIteration' '__imp_PyErr_Clear' '__imp_PyObject_RichCompare' '__imp_PyErr_SetNone' '__imp_PyLong_Type' '__imp_PyNumber_Long' '__imp__Py_FalseStruct' '__imp_PyNumber_Multiply' '__imp__Py_TrueStruct' '__imp_PyUnicode_Replace' '__imp_PyList_New' '__imp_PyTuple_Pack' '__imp_PyThreadState_Get' '__imp_PyObject_Size' '__imp_PyLong_FromSsize_t' '__imp_PyObject_Str' '__imp_PySequence_List' '__imp_PyObject_Init' '__imp_PyObject_GC_Track' '__imp_PyObject_GC_UnTrack' '__imp_PySlice_New' '__imp_PyCode_New' '__imp_PyLong_FromLong' '__imp_PyType_Ready' '__imp_PyObject_GenericGetAttr' '__imp_PyModuleDef_Init' '__imp_PyInterpreterState_GetID' '__imp_PyExc_ImportError' '__imp_PyErr_SetString' '__imp_PyObject_GetAttrString' '__imp_PyDict_SetItemString' '__imp_PyErr_ExceptionMatches' '__imp_PyModule_NewObject' '__imp_PyModule_GetDict' '__imp_PyExc_RuntimeError' '__imp_PyBytes_FromStringAndSize' '__imp_PyUnicode_FromStringAndSize' '__imp_PyImport_AddModule' '__imp_PyObject_SetAttrString' '__imp_PyObject_SetAttr' '__imp_PyImport_GetModuleDict' '__imp_PyDict_GetItemString' '__imp_PyObject_GetAttr' '__imp_PyExc_NameError' '__imp_PyErr_Format' '__imp_PyObject_Call' '__imp_Py_EnterRecursiveCall' '__imp_Py_LeaveRecursiveCall' '__imp_PyExc_SystemError' '__imp_PyCFunction_Type' '__imp_PyExc_TypeError' '__imp_PyUnicode_Compare' '__imp_PyDict_Next' '__imp_PyExc_OverflowError' '__imp_PyBaseObject_Type' '__imp_PyErr_GivenExceptionMatches' '__imp_PyErr_NormalizeException' '__imp_PyException_SetTraceback' '__imp_PyTraceBack_Type' '__imp_PyObject_IsSubclass' '__imp_PyObject_CallObject' '__imp_PyException_SetCause' '__imp_PyDict_GetItemWithError' '__imp_PyExc_KeyError' '__imp_PyExc_ValueError' '__imp_PyFloat_Type' '__imp__PyUnicodeWriter_Init' '__imp__PyFloat_FormatAdvancedWriter' '__imp__PyLong_FormatAdvancedWriter' '__imp_PyObject_Format' '__imp__PyUnicodeWriter_Dealloc' '__imp__PyUnicodeWriter_Finish' '__imp_PyExc_ZeroDivisionError' '__imp_PyFloat_FromDouble' '__imp_PyNumber_InPlaceTrueDivide' '__imp_PyNumber_TrueDivide' '__imp__PyUnicode_Ready' '__imp_PyUnicode_FromKindAndData' '__imp_PyUnicode_New' '__imp__PyUnicode_FastCopyCharacters' '__imp_PyExc_UnboundLocalError' '__imp_PyImport_ImportModuleLevelObject' '__imp_PyUnicode_FromString' '__imp_PyUnicode_InternFromString' '__imp_PyObject_Free' '__imp_PyObject_ClearWeakRefs' '__imp_PyObject_GC_Del' '__imp_PyMethod_New' '__imp_PyUnicode_FromFormat' '__imp_PyTuple_GetSlice' '__imp_PyTuple_GetItem' '__imp__PyObject_GC_New' '__imp__PyObject_GetDictPtr' '__imp_PyObject_Not' '__imp_PyMem_Malloc' '__imp_PyMem_Realloc' '__imp_PyUnicode_AsUTF8' '__imp_PyCode_NewEmpty' '__imp_PyFrame_New' '__imp_PyTraceBack_Here' '__imp_Py_SetProgramName' '__imp_Py_Initialize' '__imp_PySys_SetArgv' '__imp_PyModule_Type' '__imp_PyModule_ExecDef' '__imp_PyErr_Print' '__imp_Py_FinalizeEx' '__imp_PyFunction_Type' '__imp_PyMethodDescr_Type' '__imp_PyDescr_IsData' '__imp_PyIter_Send' '__imp_PyAsyncGen_Type' '__imp_PyExc_StopAsyncIteration' '__imp__PyGen_SetStopIterationValue' '__imp_PyGen_Type' '__imp_PyCoro_Type' '__imp_PyErr_WriteUnraisable' '__imp__PyObject_CallFunction_SizeT' '__imp_PyExc_GeneratorExit' '__imp_PyObject_CallFunctionObjArgs' '__imp_PyArg_UnpackTuple' '__imp_PyObject_CallFinalizerFromDealloc' '__imp_PyRun_StringFlags' '__imp_PyExc_RuntimeWarning' '__imp_PyErr_WarnEx' '__imp_PyImport_ImportModule' '__imp_PyObject_SelfIter' '__imp_Py_GetVersion' '__imp_PyOS_snprintf' '__imp_PyUnicode_Decode' '__imp_PyObject_Hash' '__imp_PyObject_IsTrue' '__imp_PyExc_DeprecationWarning' '__imp_PyErr_WarnFormat' '__imp_PyDict_Copy' '__imp_PySequence_Tuple' '__imp__PyErr_FormatFromCause' '__imp_PyIter_Check' '__imp_PyType_Type'

Jims313
  • 1
  • 1
  • I have a main routine defined. Not a WinMain routine. – Jims313 Jun 12 '22 at 14:23
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jun 12 '22 at 14:45
  • I edited my question to make it clear I'm using cython, not cpython. My mistake. Anyway, I'm trying to create an executable using cython and the gcc compiler on Windows 10 64 bit and I'm having issues. I know the code I have is correct, since it works with pyinstaller. I'm having issues creating the executable using cython and gcc. Gcc generates a bunch of errors as I mention. Does that help? – Jims313 Jun 12 '22 at 14:58
  • my code starts like this: import src.python.app_name import sys def main(argv): src.python.app_name.main(sys.argv[0:]) if __name__ == "__main__": main(sys.argv[0:]) – Jims313 Jun 12 '22 at 15:51
  • Note that you must call Cython with the `--embed` option if you want to produce an executable – DavidW Jun 12 '22 at 18:00
  • I recently changed my cython command to have two python files in the command, so the embed doesn't work. I import from another python file and the main one is just calling that one. Embed doesn't allow more than one python program in the command list. – Jims313 Jun 12 '22 at 18:41
  • I figured it out. My library shouldn't be -L (path)\Python310\libs. It should be -L (path)\Python310. That was part of my problem. – Jims313 Jun 12 '22 at 22:09
  • This issue can be closed now. Thanks. – Jims313 Jun 13 '22 at 13:55

0 Answers0