Jump to content
Sign in to follow this  
pcplayer99

import matplotlib error

Recommended Posts

Hello,

 

I'm testing Python4Delphi . Everything is ok beforeI tested import matplotlib.

 

My environments are:

1. Windows 11;

2. Anaconda, Python 3.11.5

3. Delphi 11 CE .

4. Delphi VCL project, target platform is Windows 64.

 

Here is my test code:

import matplotlib.pyplot as plt
import sys

print(sys.version_info)
print(sys.path)

squares = [1, 4, 9, 16, 25];
plt.plot(squares);
plt.grid(True)
print('Start')
plt.show();
print('End')

 

I have ran this script in PyScripter, it's OK.

 

In Delphi,I have created a VCL project, and run the python script in it by using: PythonEngine1.ExecStrings(Memo2.Lines); 

It raise  exception: Project testDrawLine.exe raised exception class $C000008E with message 'c000008e FLOAT_DIVIDE_BY_ZERO'.

 

I commented out "import matplotlib.pyplot as plt" and the error disappears. I commented out all code but just print code and import matplotlib.pyplot, it raises the same exception. So I am sure the error is caused by "import matplotlib.pyplot".

 

I have tested add:

from io import BytesIO
from PIL import Image

There is no exception, it works fine.

 

I have checked the Python version in Delphi project and PyScripter by:

import sys
print(sys.version_info)

And I got the same version info:

procedure TForm2.Button1Click(Sender: TObject);
var
  OldControlWord: Word;
begin
  OldControlWord := Get8087CW();
  Set8087CW($133F);
  try
    PythonEngine1.ExecStrings(Memo2.Lines);
  finally
    Set8087CW(OldControlWord);
  end;
end;

sys.version_info(major=3, minor=11, micro=5, releaselevel='final', serial=0)

 

So, the same python environment, the same python code, works fine in Pyscripter and got exception in Delphi VCL project.

 

I searched online and found this: https://stackoverflow.com/questions/3933851/nan-giving-an-error-depending-on-python-startup

So, I test this code below, but it raises the same exception:

procedure TForm2.Button1Click(Sender: TObject);
var
  OldControlWord: Word;
begin
  OldControlWord := Get8087CW();
  Set8087CW($133F);
  try
    PythonEngine1.ExecStrings(Memo2.Lines);
  finally
    Set8087CW(OldControlWord);
  end;
end;

 

 

Did I miss something that cause this exception?

 

Thanks.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×