python - 在 zipapp 存档中嵌入 numpy

我想压缩一些资源以便从多个位置轻松使用它。我必须安装一些外部模块,比如 pyyamlnumpy

首先,我将这些包安装在特定位置:

python -m pip install --target=lib pyyaml numpy

然后我创建压缩库:

python -m zipapp library --output=my_library.pyd --compress

在另一个解释器中,将“my_library.pyd”添加到sys.path 后,我可以加载yaml 模块,但不能加载numpy一个:

>>> import sys
>>> from pathlib import Path
>>> sys.path.append(str(Path().absolute() / 'my_library.pyd'))
>>> import yaml
>>> import numpy
Traceback (most recent call last):
  File "D:\Documents\rdpy\packaging_tests\my_library.pyd\numpy\core\__init__.py", line 40, in <module>
  File "D:\Documents\rdpy\packaging_tests\my_library.pyd\numpy\core\multiarray.py", line 12, in <module>
  File "D:\Documents\rdpy\packaging_tests\my_library.pyd\numpy\core\overrides.py", line 6, in <module>
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\Documents\rdpy\packaging_tests\my_library.pyd\numpy\__init__.py", line 142, in <module>
  File "D:\Documents\rdpy\packaging_tests\my_library.pyd\numpy\core\__init__.py", line 71, in <module>
ImportError:

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the multiarray numpy extension module failed.  Most
likely you are trying to import a failed build of numpy.
Here is how to proceed:
- If you're working with a numpy git repository, try `git clean -xdf`
  (removes all files not under version control) and rebuild numpy.
- If you are simply trying to use the numpy version that you have installed:
  your installation is broken - please reinstall numpy.
- If you have already reinstalled and that did not fix the problem, then:
  1. Check that you are using the Python you expect (you're using D:\Apps\python-3.7\python.exe),
     and that you have no directories in your PATH or PYTHONPATH that can
     interfere with the Python and numpy versions you're trying to use.
  2. If (1) looks fine, you can open a new issue at
     https://github.com/numpy/numpy/issues.  Please include details on:
     - how you installed Python
     - how you installed numpy
     - your operating system
     - whether or not you have multiple versions of Python installed
     - if you built from source, your compiler versions and ideally a build log

     Note: this error has many possible causes, so please don't comment on
     an existing issue about this - open a new one instead.

Original error was: No module named 'numpy.core._multiarray_umath'

在 zip 存档中,我确实有一个名为 numpy\core\_multiarray_umath.cp37-win_amd64.pyd 的文件,但它显然是一个 C 编译文件。

在创建 zip 存档时,我可以做些什么来导入 numpy 吗?

最佳答案

我相信这是 zipapp 在导入一些 .c 编译文件时的问题。为了解决这个问题,我使用了 install creator .这正是我想要的,从 python 代码创建一个 .exe。

https://stackoverflow.com/questions/56838969/

相关文章:

android-studio - 安卓工作室 : Cannot get DialogFragment

sql - 如何在 AWS Athena 中编写多个 SQL 语句,如 CREATE 表(使用 CL

python - 如何使用 python 在我的 github 帐户上创建远程 git 存储库或使用

javascript - 让 WebStorm 识别 jest.setupFilesAfterEnv

c# - Asp.net core Identity登录成功重定向回登录页面

python - 如何模拟类方法的 cls 参数?

javascript - 如何将组添加到 buefy b-taginput?

reactjs - 我是否需要在功能性 React 组件中对功能 Prop 使用 useCallba

javascript - 如何在javascript中将文件移动到drive api v3中的垃圾桶

ruby - Jekyll:尽管安装了最新版本,但命令未发现问题