1

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 Win64

if i forgot some information let met know.

1 Answers1

1

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:
    print(p)

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)

peardox
  • 362
  • 1
  • 3
  • 6
  • You are my hero I added the MaskFPUExceptions(True) and now it works perfectly. thank you so much!! – aaron versfeld Jun 09 '22 at 08:56
  • 1
    Glad to be of help. I wasn't sure if you were missing the MakeFPUException(True); or not as that error was not mentioned so I thought that maybe you were getting a misleading error hence my slightly over-detailed reply. They've just released a slew of new stuff like https://github.com/Embarcadero/PythonEnviroments and https://github.com/Embarcadero/P4D-Data-Sciences which makes things easier. – peardox Jun 10 '22 at 10:18
  • Thanks I will check the new stuff you mentioned. – aaron versfeld Jun 10 '22 at 13:39
  • 1
    The PythonEngine stuff is really good once you get the hang of it. I'm just finishing off some variations on the Data-Sceiece modules to allow scipy import. End result will be the ability to run Fast Neural Style on any PC - will Git the stuff when done... – peardox Jun 11 '22 at 14:05
  • 1
    Here's a (poor) demo - https://github.com/peardox/EmbedTest/releases. Try the release Win64 version (there's a lot to compile and build instructions are on my TODO list) – peardox Jun 11 '22 at 16:44
  • Thank you men really appreciate it that you give me all this information! It will definitely help me to understand how to use the engine. – aaron versfeld Jun 13 '22 at 07:46