2

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 Answer 1

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)

Sign up to request clarification or add additional context in comments.

7 Comments

You are my hero I added the MaskFPUExceptions(True) and now it works perfectly. thank you so much!!
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 github.com/Embarcadero/PythonEnviroments and github.com/Embarcadero/P4D-Data-Sciences which makes things easier.
Thanks I will check the new stuff you mentioned.
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...
Here's a (poor) demo - github.com/peardox/EmbedTest/releases. Try the release Win64 version (there's a lot to compile and build instructions are on my TODO list)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.