Python4Delphi can't import numpy


I was curious about Python4Delphi and installed it and looked through the demos a bit. Now I wanted to install Numpy via CMD with pip this went well without errors. but now when I enter the following code in DEMO01 of Python4Delphi I get an error message. If I enter the same code in python it works. How can i solve this?

How i installed Numpy:

pip install numpy

Example code:

    import numpy as np 
print(np .__version__)

The error i got:

AttributeError: partially initialized module 'numpy' has no attribute '__version__' (most likely due to a circular import). Did you mean: '_version'?

The versions:
Delphi 11,
Python 3.10.4,
Pip 22.1,
Numpy 1.22.4 and

if i forgot some information let met know.


Can you check you’re using the same versions of python using both methods by checking what this returns…

import sys
for p in sys.path:

Carefully compare the output of that little bit of code as it’ll point out any obvious differences.

From my experiments if you’ve got more than one Python on your system things can get weird with Python4Delphi so the above should provide evidence if this is your situation.

Importing numpy should actually cause an exception anyway, just not the one you mention in your question. Importing Numpy in demo01 will trigger a div by zero unless you add a MaskFPUExceptions(True); before you execute the python

If you use an embedded Python things will get even worse for you as you’ll need to set some additional paths to import anything. The only way I’ve found to do this properly ATM is by addending paths to sys.path in a small python stub with paths constructed relative to the embedded root (Lib and Lib/site-packages incidentally)

Answered By – peardox

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published