Nuitka 在 PySide6 项目中使用 NumPy 构建警告和导入错误

问题描述 投票:0回答:1
我目前正在开发一个 PySide6 项目,并使用 Nuitka 来编译它(pyside6-deploy 命令)。在构建过程中,我遇到了警告,并且在运行时,我面临与 NumPy 相关的 ImportError。详情如下:

构建警告

构建项目时,Nuitka 输出以下警告:

Nuitka-Plugins:警告:dll 文件:按“numpy”的文件名代码进行 DLL 配置未给出结果。要么缺少条件,要么该版本的模块需要添加处理。

尽管出现此警告,构建仍成功完成。

运行时错误

但是,当我执行构建的项目时,遇到以下导入错误:

ImportError:导入 numpy 时出错:您不应该尝试从以下位置导入 numpy 它的源目录;请退出 numpy 源代码树,然后重新启动 你的Python解释器就在那里。

该错误表明该项目错误地尝试从其源目录导入 NumPy,但我已验证我没有从 NumPy 源目录中运行该项目。

最小可重现示例

在下面,您可以找到一个最小的可重现示例。 Numpy 嵌入在 NumPy 中,但我也在包的其他一些模块中直接使用它。为了构建我的环境,我使用以下命令:

pyside6-deploy --name DICON -v -f .\main.py
对于涉及的库和python我有以下版本:

Python 3.10.13 Numpy 1.26.4
这是最小的例子:

import sys import os sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__), ".."))) import numpy as np if __name__ == "__main__": print(np.linspace(0,100,100))
执行构建命令后,这是我收到的输出:

INFO:root:[DEPLOY] Start INFO:root:[DEPLOY] Using python at C:\Users\damie\anaconda3\envs\qutee\python.exe INFO:root:[DEPLOY] Creating config file C:\Users\damie\OneDrive\Desktop\Damien\AeroDelft\repositories\DCDC-MP-CTRL-PANEL\pysidedeploy.spec INFO:root:[DEPLOY] No .pyproject file found. Project file not set INFO:root:[DEPLOY] Installing dependencies INFO:root:[DEPLOY] package: nuitka==1.5.4 already installed INFO:root:[DEPLOY] package: ordered_set already installed INFO:root:[DEPLOY] package: zstandard already installed INFO:root:[DEPLOY] Creating C:\Users\damie\OneDrive\Desktop\Damien\AeroDelft\repositories\DCDC-MP-CTRL-PANEL\pysidedeploy.spec INFO:root:[DEPLOY] Deploying application INFO:root:[DEPLOY] Running Nuitka Nuitka-Plugins:WARNING: pyside6: Unwanted import of 'tkinter' that is redundant with 'PySide6' encountered. Use '--nofollow-import-to=tkinter' or uninstall it for best compatibility with pure Python execution. Nuitka-Plugins:WARNING: dll-files: DLL configuration by filename code for 'numpy' did not give a result. Either conditions are missing, or this version of the module needs treatment added. [DEPLOY] Executed file created in C:\Users\damie\OneDrive\Desktop\Damien\AeroDelft\repositories\DCDC-MP-CTRL-PANEL\main.exe INFO:root:[DEPLOY] Deployment directory purged INFO:root:[DEPLOY] End
尝试解决

    我已经确认我当前的工作目录不是NumPy源目录
  1. 在我的
  2. pysidedeploy.spec
    中指定numpy,然后使用
    main.py
    文件代替从
    .spec
    构建。您可以看到下面的配置:
[app] # title of your application title = DICON # project directory. the general assumption is that project_dir is the parent directory # of input_file project_dir = . # source file path input_file = C:\Users\damie\OneDrive\Desktop\Damien\AeroDelft\repositories\DCDC-MP-CTRL-PANEL\main.py # directory where exec is stored exec_directory = . # path to .pyproject project file project_file = [python] # python path python_path = C:\Users\damie\anaconda3\envs\qutee\python.exe # python packages to install # ordered-set = increase compile time performance of nuitka packaging # zstandard = provides final executable size optimization packages = nuitka==1.5.4,ordered_set,zstandard, numpy==1.26.4 # buildozer = for deploying Android application android_packages = buildozer==1.5.0,cython==0.29.33 [qt] # comma separated path to qml files required # normally all the qml files are added automatically qml_files = # excluded qml plugin binaries excluded_qml_plugins = # path to pyside wheel wheel_pyside = # path to shiboken wheel wheel_shiboken = # plugins to be copied to libs folder of the packaged application. comma separated plugins = platforms_qtforandroid [nuitka] # (str) specify any extra nuitka arguments # eg = extra_args = --show-modules --follow-stdlib extra_args = --quiet --noinclude-qt-translations=True [buildozer] # build mode # possible options = [release, debug] # release creates an aab, while debug creates an apk mode = debug # contrains path to pyside6 and shiboken6 recipe dir recipe_dir = # path to extra qt android jars to be loaded by the application jars_dir = # if empty uses default ndk path downloaded by buildozer ndk_path = # if empty uses default sdk path downloaded by buildozer sdk_path = # modules used. comma separated modules = # other libraries to be loaded. comma separated. # loaded at app startup local_libs = plugins_platforms_qtforandroid # architecture of deployed platform # possible values = ["aarch64", "armv7a", "i686", "x86_64"] arch =
问题:

    如何解决 Nuitka 发出的有关 NumPy 的 DLL 警告,以确保它正确处理依赖项?
  1. 可能导致 ImportError 的原因是什么以及如何解决它以正确导入 NumPy 而不会出现错误?
numpy pyside6 python-3.10 nuitka deploying
1个回答
0
投票
基于这个

问题,我认为我的问题是由我使用 pip 安装 Numpy 引起的。所以我使用pip uninstall numpy

卸载,然后使用
conda install numpy
再次安装。这解决了我的 DLL 问题。

© www.soinside.com 2019 - 2024. All rights reserved.