mobiusklein / cython_pyinstaller_example

A simple example repository describing the process of building a PyInstaller executable for a Cython-compiled program
50 stars 11 forks source link

Excellent tutorial for Cython+PyInstaller, But more help needed. #2

Open gaamaaresosa opened 1 year ago

gaamaaresosa commented 1 year ago

@mobiusklein First of all thank you so much for your effort. While I was searching similar concept, luckily I got this post. Though you had taken good efforts to explain the steps, its bit hard to understand as some more steps missing in between.

Btw, will the output binarry is still Bytecode or native machine language binary. I am interested the main code should be native machine language binary. And may be the PyInstaller loader binary could be any.

Kindly correct me where I am wrong. In future if you have time, please make better tutorial on this same topic. Or refer me similar topic is some one already done.

I tried my best to fill that steps and no success yet.

1) No proper command line to execute setup.py I used below command, see the error and confused. And expected "app.c", "app.so", "calc.c" and "calc.so" files inside my_package folder But only "app.c", "calc.c" produced. Where are the "app.so" and "calc.so" files. Or this is what expected ?

BAD CALL: $ sudo python3 ./setup.py
GOOD CALL:  $ sudo python3 setup.py build_ext --inplace
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help

error: no commands supplied

2) What next ? I trying runing build.sh from pyinstaller folder.

$ sudo ./build.sh
Beginning build
493 INFO: PyInstaller: 5.10.1
494 INFO: Python: 3.7.3
497 INFO: Platform: Linux-6.1.23-v8+-aarch64-with-debian-10.13
498 INFO: wrote /home/pi/Cython_PyInstaller_Test/pyinstaller/my_mandelbrot.spec
509 INFO: UPX is available.
512 INFO: Extending PYTHONPATH with paths
... more lines...

68101 INFO: Building COLLECT COLLECT-00.toc
71575 INFO: Building COLLECT COLLECT-00.toc completed successfully.

3) Now I could see the executable "my_mandelbrot", 100s of files and some folders at /home/pi/Cython_PyInstaller_Test/pyinstaller/dist/my_mandelbrot

After running that binary I get below error. Lost interest... May be main reason is extra new bundles (numpy, matplotlib )

Of course I have installed numpy, matplotlib, PyInstaller and Cython I have followed the directory tree as you had suggested.

Path

 $ sudo ./my_mandelbrot
Traceback (most recent call last):
  File "my_mandelbrot.py", line 6, in <module>
ModuleNotFoundError: No module named 'my_package'
[26831] Failed to execute script 'my_mandelbrot' due to unhandled exception!

System: Raspberry Pi 4 Linux buster 32bit OS

Note: Kindly avoid using extra packages while explaing a new concept with simple project. Here numpy, matplotlib could have been avoided as the numpy hangs for 30mins to install. I got diverted from the understanding thread.

A big thanks again !

gaamaaresosa commented 1 year ago

After few hours of experiment I made this code to work. 1) sudo python3 setup.py build_ext --inplace (NOT sudo python3 setup.py) app.cpython-37m-arm-linux-gnueabihf.so calc.cpython-37m-arm-linux-gnueabihf.so These 2 .so files I got it as expected.

2) I have to move "my_package" folder to
/home/pi/.gstreama/Cython_PyInstaller_Test/pyinstaller/dist/my_mandelbrot/

If the expert authors spend another few seconds and write proper lines People like me with half knowledge on linux could see success.

Thanks to this author again !

mobiusklein commented 1 year ago

@gaamaaresosa I've modified the README to include details about how to invoke the setup.py script. Do those steps work when you try to build the executable?

gaamaaresosa commented 1 year ago

@gaamaaresosa I've modified the README to include details about how to invoke the setup.py script. Do those steps work when you try to build the executable?

Thank you so much again. I will test it.

gaamaaresosa commented 1 year ago

I tried several times and no success yet. Main reason I doubt is extra matplotlib installation. The error showing on that one.

Its a very good topic. But hard to undersatnd the nested logic. If any one do better tutorial without installing extra packages like numpy and matplotlib. That could easily be followed. Experts may not need these tutorials because they are experts. But always think of us.

Any how let me try to understand it...

numpy installation hangs for ever: I tried 3 times and no success. No more patients...

image


11631 INFO: Appending PKG archive to custom ELF section in EXE
11645 INFO: Building EXE from EXE-00.toc completed successfully.
11648 INFO: checking COLLECT
11648 INFO: Building COLLECT because COLLECT-00.toc is non existent
11648 INFO: Building COLLECT COLLECT-00.toc
12074 INFO: Building COLLECT COLLECT-00.toc completed successfully.
raspberry@pi:~/.raspberry/Cython_PyInstaller_Test/pyinstaller $ cd /home/raspberry/.raspberry/Cython_PyInstaller_Test/pyins        taller/dist/my_mandelbrot
raspberry@pi:~/.raspberry/Cython_PyInstaller_Test/pyinstaller/dist/my_mandelbrot $ sudo my_mandelbrot
sudo: my_mandelbrot: command not found
raspberry@pi:~/.raspberry/Cython_PyInstaller_Test/pyinstaller/dist/my_mandelbrot $ sudo ./my_mandelbrot
Traceback (most recent call last):
  File "my_mandelbrot.py", line 2, in <module>
ModuleNotFoundError: No module named 'matplotlib'
[20539] Failed to execute script 'my_mandelbrot' due to unhandled exception!
raspberry@pi:~/.raspberry/Cython_PyInstaller_Test/pyinstaller/dist/my_mandelbrot $```

After installing success also I see same error.

```  Created wheel for numpy: filename=numpy-1.21.6-cp37-cp37m-linux_aarch64.whl size=14967401 sha256=e827f6c9839449e28d553f7060b95e9c42ef03d6d80a2824be69a4390334479a
  Stored in directory: /root/.cache/pip/wheels/4e/7e/9e/0fde042ccff2493994076dac9c3fbd78feb444c3bd94eb386a
Successfully built numpy
Installing collected packages: python-dateutil, packaging, numpy, kiwisolver, fonttools, cycler, matplotlib
  Attempting uninstall: numpy
    Found existing installation: numpy 1.16.2
    Uninstalling numpy-1.16.2:
      Successfully uninstalled numpy-1.16.2
Successfully installed cycler-0.11.0 fonttools-4.38.0 kiwisolver-1.4.4 matplotlib-3.5.3 numpy-1.21.6 packaging-23.1 python-dateutil-2.8.2
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
raspberry@pi:~/.raspberry/Cython_PyInstaller_Test/pyinstaller/dist/my_mandelbrot $ sudo ./my_mandelbrot
Traceback (most recent call last):
  File "my_mandelbrot.py", line 2, in <module>
ModuleNotFoundError: No module named 'matplotlib'
[21671] Failed to execute script 'my_mandelbrot' due to unhandled exception!
raspberry@pi:~/.raspberry/Cython_PyInstaller_Test/pyinstaller/dist/my_mandelbrot $```

NOTE:
LINUX OS IS NOT STABLE LIKE WINDOWS
ON EVERY UPDATE SOMETHING OR OTHER WILL NOT WORK.
TODAY IF YOU MAKE SOME TUTORIAL NEXT YEAR IT WILL THROW ERRORS.
SO NO EXTRA PACKAGES TO EXPLAIN SOME IMPORTANT TOPIC.