1

For moderators: this question didn't help me, so please dont mark this as a duplicate, thanks :)


I have finally compiled the cython c code into an executable withnout any errors, but i can't run it on any machine withnout python installed.

To generate and compile the code, i used cython and the gcc compiler.
and my OS is windows 10

Also, i need to make a portable exe, not an installer, or a self extracting archive.

i am not sure if i provided enough infomation, if you need to konw anything just ask me in the comments :P

I can't find anything that would solve this issue, so i would really appreciate any help :)


To create the Cython C code, i used this command:

cython -3 --embed main.py

To compile the generated code, i used this command:

gcc main.c --static -I "C:\Program Files\Python39\include" -L "C:\Program Files\Python39\libs" -lpython39 -municode -o main.exe

This is the error message i am getting (on the machine withnout python):

error

Thanks :)

Damca
  • 50
  • 1
  • 8
  • "For moderators: this question didn't help me, so please dont mark this as a duplicate, thanks :)". Just so you know moderators are not the only ones who mark questions as duplicates :). – Buddy Bob Jun 15 '21 at 16:09
  • 1
    oh okay, thanks for telling me :) – Damca Jun 15 '21 at 16:51
  • I think the answer is probably "Cython is not really the tool for this, use something like PyInstaller or similar instead" – DavidW Jun 15 '21 at 17:07
  • You should not delete the old one (https://stackoverflow.com/q/67987279/5769463) but edit it and explain, why it is not a duplicate. “It didn’t help me” isn’t an explanation. Obviously you need at least to distribute libpython-dll. Once it is done you will see all other things from duplicate are needed as well. – ead Jun 15 '21 at 18:11
  • If you want to link statically against libpython, you shouldn’t do it even if you can: https://stackoverflow.com/q/62492622/5769463 – ead Jun 15 '21 at 18:15
  • @DavidW well i dont want the executable to be eazily decompiled, and i want it to be fast so pyinstaller isn't probably good for this – Damca Jun 15 '21 at 18:45
  • @ead thanks for the advice :) also, if i edit it, will it be opened again? i am still kinda new to stack overflow so i dont know how this works. – Damca Jun 15 '21 at 18:47
  • and thanks for the link, i aprreciate it :) – Damca Jun 15 '21 at 18:48
  • @Damca it depends on your edit - if it doesn't get clear what you want (what does "a portable exe" even means) and why the proposed solution from the duplicate isn't satisfactory, the chances for reopening are slim. – ead Jun 15 '21 at 19:53
  • @ead thanks for clarifying. By the way, i tried [doing this](https://stackoverflow.com/questions/62492622/statically-link-python37-dll-and-vcruntime140-dll-when-using-cython-embed), but i keep getting this error: `main.c(1983): error C2198: PyCode_New: too few arguments for call`. Do you know how to fix this? Thanks :) – Damca Jun 21 '21 at 08:20
  • also, i am using this command to compile the code: `cl /c main.c /Fomain.obj /D "Py_NO_ENABLE_SHARED" /nologo /Ox /W3 /GL /DNDEBUG /MD -I"C:\Users\Damča\Desktop\cpython-main\Include" -I"C:\Users\Damča\Desktop\cpython-main\PC"` – Damca Jun 21 '21 at 08:22
  • I have no idea. By the look of it, you are using the main-branch of cpython, which is probably not yet supported by cython version you are having. I would try 3.9 branch or 3.8. – ead Jun 21 '21 at 08:40
  • @ead Thanks, it compiled withnout errors now. But i got another [error](https://pastebin.com/Dz3YiU6S) while trying to run the executable on a machine withnout python installed though. What i am i doing wrong? – Damca Jun 21 '21 at 18:56
  • You need Python's standard libraries see the first duplicate-target or this https://stackoverflow.com/a/56861396/5769463 with more gory details. – ead Jun 21 '21 at 19:09

1 Answers1

0

Maybe you need it to add it in your environments variables?

Panchito
  • 16
  • 3
  • 1
    I probably forgot to clarify that it runs only on a machine with python installed (or with python39.dll in the same folder as the exe), my goal is to make a portable exe, so i dont have to have python installed to run it. So this isn't quite the problem. Thanks anyways :) – Damca Jun 15 '21 at 16:49