Recent

Author Topic: Python4Lazarus Undefined symbol: PyExc_ValueError  (Read 2139 times)

Grew

  • New member
  • *
  • Posts: 9
Python4Lazarus Undefined symbol: PyExc_ValueError
« on: December 03, 2024, 01:57:41 am »
I have inherited an old but essential app that connected from lazarus to LinuxCNC through PythonForLazarus.  The older version has been running on python 2.7 for many years.  Owing to the need to software upgrade I am trying to reconfigure to newer installation.  So I am at this point:-

- I can use CLI to connect to linuxCNC and have no problems. 

- Demo Python packages from LinuxCNC run with no problem.

- A test application set up as per the video on Youtube by Al As works exactly as expected.

So it seem that the configurations are correct, however as soon as I enter the python command "import linuxcnc" I get the PyExc_ValueError.  (I do not get any error for this in the CLI)

OS Debian12  installed from linuxCNC's live distro with PreemptRT.
Lazarus 3.4 and FPC 3.2  as installed with fpcupdeluxe.
Python 3.11 ( required for linuxCNC?)

I did an environment comparison between the CLI and Python4Lazarus setups.  The results show only that Python4Lazarus did not have the Pythonpath set.  I added that to the Pythonengine property, but to no avail. ( I attempted a few other methods as well)

  PythonEngine1.PythonPath := '/usr/lib/python3/dist-packages';

I have spent two day solid fighting with this. I am not an experienced programmer so I have probably overlooked something obvious. (please be patient) I have trawled the forums and run all the AI's dry.   I urgently need assistance:(

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1255
Re: Python4Lazarus Undefined symbol: PyExc_ValueError
« Reply #1 on: December 04, 2024, 02:07:28 am »
Hello,
look at attachment my PythonEngine settings working on Ubuntu 20.04  Lazarus 2.2
be sure that there is no multiple python versions on your os or connect pythonEngine to your 3.11 version via settings.
Friendly, J.P
« Last Edit: December 04, 2024, 02:16:13 am by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

Grew

  • New member
  • *
  • Posts: 9
Re: Python4Lazarus Undefined symbol: PyExc_ValueError
« Reply #2 on: December 05, 2024, 06:13:04 pm »
I do have to thank you J.P.  I do believe it was the correct DllPath that got me over the line. %)

AlexTP

  • Hero Member
  • *****
  • Posts: 2520
    • UVviewsoft
Re: Python4Lazarus Undefined symbol: PyExc_ValueError
« Reply #3 on: December 05, 2024, 08:42:33 pm »
  PythonEngine1.PythonPath := '/usr/lib/python3/dist-packages';

I am not sure this works at all.
in CudaText i never use PythonPath prop.
and Python4Lazarus main aim is CudaText.
CudaText uses this code

Code: Pascal  [Select][+][-]
  1.   PythonEng.UseLastKnownVersion:= False;
  2.   PythonEng.DllPath:= ExtractFilePath(SLibItem);
  3.   PythonEng.DllName:= ExtractFileName(SLibItem);
  4.   PythonEng.LoadDll;

so try to use DllPath/DllName props.

Grew

  • New member
  • *
  • Posts: 9
Re: Python4Lazarus Undefined symbol: PyExc_ValueError
« Reply #4 on: December 06, 2024, 12:03:45 pm »
Just to clarify, it was DllPath set to /usr/lib/x86_64-linux-gnu/ that fixed it for me.  And yes, I dropped the PythonPath property.

(You know, when you don't know, you just don't know. ;D  )

Of interest, this app also uses

   DllPath := ExtractFilePath

method, but the parameter was hard coded into the App as:- 

/usr/lib/libpython2.7.so.1.0'

which worked fine for the old version.

In your case what is the origin of SLibItem (hope it's not a stupid question?)

AlexTP

  • Hero Member
  • *****
  • Posts: 2520
    • UVviewsoft
Re: Python4Lazarus Undefined symbol: PyExc_ValueError
« Reply #5 on: December 06, 2024, 02:26:25 pm »
In CudaText, origin of SLibItem is the option "pylib__linux" which user writes to user.json config.

Grew

  • New member
  • *
  • Posts: 9
Re: Python4Lazarus Undefined symbol: PyExc_ValueError
« Reply #6 on: December 30, 2024, 01:04:55 pm »
So I went down this rabbit hole again.  Had further problems with my live install, but then travelled for Xmass. I wanted to play with the setup so installed the exact same environment on a VirtualBox.

The DLLPath setting alone did not help me this time, so I have a log of all the changes I made.  I cannot be sure that everything was required but I am listing here for anyone else that comes across the issue.

### Summary of Actions Taken to Resolve Lazarus-Python Integration Issue

1. **Tested first with Simple App from Al As  - https://www.youtube.com/@178alaa **:
   - Verified that the Lazarus app compiled but the window would immediately close again when using the `pythonforlazarus` library.
   - Confirmed that Python was indeed functioning correctly and interacted correctly with other apps via the CLI(bash).
   - Opening of the window was resolved by applying the scrollbar to the TMemo. Why, I do not know.  I initially missed this step and thought it not required.

2. **Dependencies and Environment**:
   - Ensured all necessary dependencies for Lazarus and Python were installed.
   - Installed `python3-dev` libraries to provide header files and static library for Python development.

3. **Configuration in Lazarus**:
   - Set `DllPath` to `/usr/lib/x86_64-linux-gnu` and `DllName` to `libpython3.11.so.1.0`.
   - Set environment variables in `.bashrc`:
     ```bash
     export PYTHONHOME=/usr
     export PYTHONPATH=/usr/lib/python3.11
     export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu
     ```

4. **Adjusting Lazarus Component Settings**:
   - Set `AutoUnload` to True, `FatalAbort` to True, `InitThreads` to True, and `uselastknownversion` to False in the `pythonforlazarus` component settings(object inspector).

5. **Resolving UI Issues**:
   - Ticked the scrollbar setting in the Memo component to prevent the window from closing immediately after startup.
   - In my other app, Set `LIBOVERLAY_SCROLLBAR` to `0` to address UI-related issues.

6. **Debugging with `strace` and `LD_DEBUG`**:
   - Used `strace` to trace system calls and signals:
     ```bash
     strace -f -o trace.log ./YourApplication
     ```
   - Set `LD_DEBUG` to `libs` for detailed information about library loading:
     ```bash
     LD_DEBUG=libs ./YourApplication
     ```

One or a combination of the above got the test app working and thus my own app as well( Pythonforlazarus not implemented as a UI component).

AlexTP

  • Hero Member
  • *****
  • Posts: 2520
    • UVviewsoft
Re: Python4Lazarus Undefined symbol: PyExc_ValueError
« Reply #7 on: December 30, 2024, 02:06:22 pm »
All this is unclear to me - what do you suggest for my git repo of Python4Lazarus?
https://github.com/Alexey-T/Python-for-Lazarus

 

TinyPortal © 2005-2018