0

我正在尝试使用使用 skyfield 模块/API 的 pyinstaller 打包一个脚本,并且它会构建,但是当我运行它时,它会说找不到nutation.npz(包含在nutationlib.py _arrays = load_bundled_npy('nutation.npz').

我尝试过使用--onefile,而不是使用它。--add-data并且--add-binary不喜欢它。--hidden-imports没有帮助。--debug=imports不是太有用,但附加的日志来自--debug=all编译。

关于如何强制 pyinstaller 将 nutation.npz 包含到内置的 .exe 中的任何想法,以便在提取/运行时它在那里?

import skyfield.nutationlib # PyInstaller PYZ
Traceback (most recent call last):
  File "satvis.py", line 9, in <module>
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "c:\users\fox\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages\skyfield\api.py", line 11, in <module>
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "c:\users\fox\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages\skyfield\constellationlib.py", line 29, in <module>
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "c:\users\fox\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages\skyfield\timelib.py", line 14, in <module>
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "c:\users\fox\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages\skyfield\nutationlib.py", line 7, in <module>
  File "site-packages\skyfield\functions.py", line 143, in load_bundled_npy
  File "pkgutil.py", line 637, in get_data
  File "c:\users\fox\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 471, in get_data
    with open(path, 'rb') as fp:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\fox\\AppData\\Local\\Temp\\_MEI89762\\skyfield\\data\\nutation.npz'
[44412] Failed to execute script satvis
4

3 回答 3

1

您需要添加一个包含skyfield数据文件(npz、npy 等)的目录。

例如,如果skyfield位于虚拟环境文件夹中,则需要以下pyinstaller调用:

pyinstaller --onefile --add-data 'venv/Lib/site-packages/skyfield/data;skyfield/data' yourapp.py
于 2021-04-30T08:53:11.983 回答
0

在 Skyfield 的代码中,看起来它认为该文件属于包“skyfield”:

data = get_data('skyfield', 'data/{0}'.format(filename))

但在 Skyfield'ssetup.py中,该文件属于子包skyfield.data

package_data = {
    'skyfield': ['documentation/*.rst'],
    'skyfield.data': ['Leap_Second.dat', 'deltat.data', 'deltat.preds',
                      '*.npy', '*.npz'],
    'skyfield.tests': ['data/*'],
    },

如果您有能力编辑 Skyfield 的本地副本,请尝试更改上面引用的代码行skyfield/functions.py,使其显示:

data = get_data('skyfield.data', '{0}'.format(filename))

更改有可能解决 PyInstaller 的问题。如果是这样,我将正式更改 Skyfield 的代码!

于 2020-07-28T18:26:41.090 回答
0

我能够在 Win10 上构建 myprog.exe 的工作“onefile”

python 3.7.9
pyinstaller 4.0
天域 1.29

通过使用命令构建规范文件

pyinstaller -F myprog.py

然后在规范文件中,更改行

datas=[],

datas=[ ('C:\\Users\\Administrator\\Anaconda3\\pkgs\\skyfield-1.28-pyh9f0ad1d_0\\site-packages\\*', 'skyfield')],

我使用的构建命令是

pyinstaller -clean myprog.spec

我不相信 Anaconda 与它有任何关系,这就是我的安装有 skyfield 包数据的地方。但是,我确实在标准的 Python 虚拟环境中构建了它。

于 2020-09-27T00:29:17.597 回答