简体   繁体   English

Python4Delphi 无法导入 numpy

[英]Python4Delphi can't import numpy

I was curious about Python4Delphi and installed it and looked through the demos a bit.我对Python4Delphi很好奇并安装了它并浏览了一些演示。 Now I wanted to install Numpy via CMD with pip this went well without errors.现在我想通过 CMD 和 pip 安装Numpy ,这很顺利,没有错误。 but now when I enter the following code in DEMO01 of Python4Delphi I get an error message.但是现在当我在 Python4Delphi 的Python4Delphi中输入以下代码时,我收到一条错误消息。 If I enter the same code in python it works.如果我在python中输入相同的代码,它就可以工作。 How can i solve this?我该如何解决这个问题?

How i installed Numpy:我是如何安装 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版本:Delphi 11、Python 3.10.4、Pip 22.1、Numpy 1.22.4 和 Win64

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...你能通过检查返回的内容来检查你使用这两种方法使用相同版本的python吗?

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.从我的实验来看,如果你的系统上有多个 Python,Python4Delphi 可能会变得很奇怪,所以如果这是你的情况,上面应该提供证据。

Importing numpy should actually cause an exception anyway, just not the one you mention in your question.无论如何,导入 numpy 实际上应该会导致异常,而不是您在问题中提到的那个。 Importing Numpy in demo01 will trigger a div by zero unless you add a MaskFPUExceptions(True);在 demo01 中导入 Numpy 将触发 div 为零,除非您添加MaskFPUExceptions(True); before you execute the python在执行 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.如果您使用嵌入式 Python,情况会变得更糟,因为您需要设置一些额外的路径来导入任何内容。 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)我发现正确执行此操作的唯一方法 ATM 是在一个小的 python 存根中添加 sys.path 的路径,其中路径是相对于嵌入式根目录构建的(顺便说一下 Lib 和 Lib/site-packages)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM