Lazarus

Programming => General => Topic started by: suibaf on July 05, 2022, 09:53:04 pm

Title: python for lazarus
Post by: suibaf on July 05, 2022, 09:53:04 pm
Hi,
I'm trying to permit to work to a app that I found on youtube that is an example of python for lazarus:

https://www.youtube.com/watch?v=WREEoECCMy0

In general it work, with simply python command, but if I try to run a python example of matplotlib with lazarus app it give me an error.

If I run the same python code with Idle or Thonny it work fine. The lazarus give me this error:

---------------------------------------------------------------------------------------------------------------------------------------------------------------------
ImportError:

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.8 from "/usr/bin/python3"
  * The NumPy version is: "1.23.0"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: /home/fabio/.local/lib/python3.8/site-packages/numpy/core/_multiarray_umath.cpython-38-x86_64-linux-gnu.so: undefined symbol: PyObject_SelfIter
.

Press OK to ignore and risk data corruption.
Press Abort to kill the program
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Can you help me to understand what is the problem?
I run with lazarus 2.2.2 on Linux Mint.
BR



Title: Re: python for lazarus
Post by: mercurhyo on July 06, 2022, 02:37:24 am
so the error said itself ... "IMPORTANT... SEE NUMPY" I guess you should ask NUMPY if any forum
Title: Re: python for lazarus
Post by: Jurassic Pork on July 06, 2022, 03:48:32 am
hello,
how have you installed the module matplotlib ? with pip ? with apt-get install ?
I have no problem on Ubuntu 20.04 Lazarus 2.2  Last version of Python4Lazarus python 3.8 to import matplotlib in a python script used by Python4Lazarus.
matplotlib installed with the command :
Quote
apt-get install python3-matplotlib
Friendly, J.P
Title: Re: python for lazarus
Post by: suibaf on July 06, 2022, 01:45:28 pm
I'm going to try to reinstall matplotlib, but if I run the python code with thonny or with Pycharm it work fine!

No work inside the lazarus app.

Thank you
Title: Re: python for lazarus
Post by: suibaf on July 06, 2022, 09:05:59 pm
As yuo can see with thonny the code python work, inside the lazarus app no!
Thank you
Title: Re: python for lazarus
Post by: AlexTP on July 06, 2022, 10:10:23 pm
I am not sure Python4Lazarus lacks something, yes it lacks 'PyObject_SelfIter' symbol, but Python4Delphi (original project) lacks it too!
Title: Re: python for lazarus
Post by: Jurassic Pork on July 07, 2022, 07:15:22 am
Hello,
As yuo can see with thonny the code python work, inside the lazarus app no!
No problem to run your python script in Lazarus on Ubuntu 20.04 (see attachment).
the packages numpy and matplotlib are in the folder /usr/lib/python3/dist-packages
Friendly, J.P
Title: Re: python for lazarus
Post by: suibaf on July 07, 2022, 10:41:41 am
I'm newbie of Lazarus, so I don't know what can I do.
Can you send me your code?
BR
Title: Re: python for lazarus
Post by: Jurassic Pork on July 07, 2022, 11:48:42 am
in attachments, lazarus project using Python4Lazarus and matplotlib
MAy be you need to change the properties  DllName, DllPath and regVersion of the TPythonEngine component (see attachment for an example).
Friendly, J.P
Title: Re: python for lazarus
Post by: suibaf on July 07, 2022, 08:59:48 pm
Your app work perfectly!
Title: Re: python for lazarus
Post by: suibaf on July 08, 2022, 04:51:12 pm
As I said your app work very well, but if I calcel pythonengine from the form and then I put on the form new pythonengine it does not work, also if I write correct reference to dllname and dllpath. There is something in my system that is corrupt.

BR
Title: Re: python for lazarus
Post by: Mongkey on June 07, 2023, 05:40:38 am
I was trying on windows 7,
python_console -> it failed -> open & suddenly closed, all dll, DLLs, pythonxx.zip already there,
python_thread -> it failed -> seems zip file not extracted just like on arduino IDE esp framework fault,

how to solve this?

Thank you!
Title: Re: python for lazarus
Post by: Mongkey on June 09, 2023, 06:23:44 am
I did it on ubuntu, but i got another problem, if i try to import cv2 it always say cv2 has no member __version__?

I checked it has installed cv2 version 3.2.0

Thank you

python script to exec:
Code: Python  [Select][+][-]
  1. import cv2
  2. print(cv2.__version__)
  3.  
Title: Re: python for lazarus
Post by: Jurassic Pork on June 10, 2023, 09:36:33 am
Hello,
What is your version of Ubuntu ? and the version of Lazarus ? it seems you have an old version of opencv. Have you installed the package python3-opencv ? On Ubuntu 20.04 with Lazarus 2.2.4 i have no problem to import cv2 and print the version (see attachment). And if you want only use python to use opencv don't forget the lazarus package : Opencv version 4.6 C++ API wrapper (https://forum.lazarus.freepascal.org/index.php/topic,62900.msg475903.html#msg475903)

Code: Pascal  [Select][+][-]
  1. implementation
  2. uses  OPENCVWrapper;
  3. {$R *.lfm}
  4.  
  5.  
  6. procedure TForm6.btnStartClick(Sender: TObject);
  7. var
  8.     version: AnsiString;
  9.  
  10. begin
  11.   version := pCvgetVersionString().pstr;
  12.   ShowMessage('OpenCv Version : ' + version);
  13. end;    
  14.  

Friendly, J.P
Title: Re: python for lazarus
Post by: Mongkey on June 11, 2023, 01:38:50 am
Thank you for your fast respone JP,

my ubuntu is 18.04
lazarus 2.2.4

Update:
I already did, all readme.txt of opencvwrapper, seems this wrapper is not for me, i would like to use python as http server and opencv image processor, it quite easy than combining pascal + python. Thank you.
TinyPortal © 2005-2018