pyscripter/python4delphi

Pandas with Python 3.12

comdora opened this issue · 13 comments

Hi, using your demo1, I have tried to compile next python scrip

import numpy as np
import pandas as pd

rg = np.random.default_rng()

def generate_data(n_features, n_values):
features = rg.random((n_features, n_values))
weights = rg.random((1, n_values))[0]
targets = np.random.choice([0,1], n_features)
data = pd.DataFrame(features, columns=["x0", "x1", "x2"])
data["targets"] = targets
return data, weights

data, weights = generate_data(4,3)
print(data)

I have received next messages:
Traceback (most recent call last):
File "", line 2, in
File "C:\Users\ivan\AppData\Local\Programs\Python\Python312\Lib\site-packages\pandas_init_.py", line 62, in
from pandas.core.api import (
File "C:\Users\ivan\AppData\Local\Programs\Python\Python312\Lib\site-packages\pandas\core\api.py", line 47, in
from pandas.core.groupby import (
File "C:\Users\ivan\AppData\Local\Programs\Python\Python312\Lib\site-packages\pandas\core\groupby_init_.py", line 1, in
from pandas.core.groupby.generic import (
File "C:\Users\ivan\AppData\Local\Programs\Python\Python312\Lib\site-packages\pandas\core\groupby\generic.py", line 68, in
from pandas.core.frame import DataFrame
File "C:\Users\ivan\AppData\Local\Programs\Python\Python312\Lib\site-packages\pandas\core\frame.py", line 149, in
from pandas.core.generic import (
File "C:\Users\ivan\AppData\Local\Programs\Python\Python312\Lib\site-packages\pandas\core\generic.py", line 193, in
from pandas.core.window import (
File "C:\Users\ivan\AppData\Local\Programs\Python\Python312\Lib\site-packages\pandas\core\window_init_.py", line 1, in
from pandas.core.window.ewm import (
File "C:\Users\ivan\AppData\Local\Programs\Python\Python312\Lib\site-packages\pandas\core\window\ewm.py", line 11, in
import pandas._libs.window.aggregations as window_aggregations
ImportError: DLL load failed while importing aggregations: The specified module could not be found.

But, same script is executed from command prompt and result is shown on the attached image. (I am in process of learning Python4Delphi)
Screenshot 2024-04-12 at 18 54 42

Thanks in advance
Bojan

Thanks for your answer. I have only one python version installed on the computer, and dll's can't be messed. Also, as you can see on the image, script works when it is executed "directly".

I have tested on other computer, Delphi 12.0, Python 3.11, script is executed OK.
On the computer with Delphi 12.1, Python 3.12 error still exists. Script execution from command prompt, on the both computers is executed OK.

Result := PyEval_EvalCode(Code, _globals, _locals );

line 5153 in PythonEngine, Result is nil

Cannot reproduce.
I am using Delphi 12.1 and python 3.12.2 from python.org,
Using Demo01 with PythonEngine1.UseLastKnownVersion set to True.

image

Your script also runs fine.
Sounds like a python/pandas installation issue.

@comdora As I said above, it appears to be a python/pandas installation issue. It is not related to the Delphi version, since we are using the same version.

If you google for "ImportError: DLL load failed while importing aggregations: The specified module could not be found" you will see it has happened to others and typically gets resolved by uninstalling/reinstalling pandas and possibly python.
Also please make sure you are using the latest version (master branch) of P4D, from this repo.

I have reinstalled few times the pandas library
Screenshot 2024-04-13 at 01 05 31
I had been installed P4D from Getit, but few minutes aga I had uninstalled it and have installed from the Github master. Result is same

Screenshot 2024-04-13 at 01 26 49

But result of execution without P4d is shown on the next picture

Screenshot 2024-04-13 at 01 27 50

I have installed python 3.12.3 to make sure we are using the same python version and it still works fine here.

We are using the same Delphi, python and P4D versions and here it works and at your side it doesn't. I have no idea why. And if I cannot reproduce the error, I cannot fix it.

Can you try one last thing?

Try running:

import sys
print(sys.path)

What do you get?

Cannot reproduce and no feedback.