我是pyinstaller的新手,正在运行.exe时遇到FileNotFoundError
。命令行输出如下:
c:\users\###\appdata\local\programs\python\python37-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py:627: MatplotlibDeprecationWarning:
The MATPLOTLIBDATA environment variable was deprecated in Matplotlib 3.1 and will be removed in 3.3.
exec(bytecode, module.__dict__)
Traceback (most recent call last):
File "<script-name>", line 31, 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\###\appdata\local\programs\python\python37-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\cfgrib\__init__.py", line 19, 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\###\appdata\local\programs\python\python37-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\cfgrib\cfmessage.py", line 28, 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\###\appdata\local\programs\python\python37-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\cfgrib\messages.py", line 36, 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\###\appdata\local\programs\python\python37-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\cfgrib\bindings.py", line 32, in <module>
File "pkgutil.py", line 637, in get_data
File "c:\users\###\appdata\local\programs\python\python37-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 475, in get_data
with open(path, 'rb') as fp:
FileNotFoundError: [Errno 2] No such file or directory: '<file-location\\<script_name>\\cfgrib\\grib_api.h'
[6472] Failed to execute script <script-name>
该问题似乎与cfgrib软件包有关。当我运行.exe时,不会创建cfgrib模块的生成目录。因此,找不到grib_api.h
文件,因为从未创建目录。
我尝试在anaconda和pip中构建.exe,在两种情况下都发现相同的错误。
我还尝试将带有--add-data
标志的pyinstaller .spec文件重新映射到计算机上grib_api.h
的其他位置,但是无法正常工作。见下文。
pyinstaller --onedir --add-data "<source-path>\cfgrib\grib_api.h; <destination-path>\cfgrib" <script-name>
我实现了后者以解决另一个丢失文件的错误,但是我认为在这种情况下它不起作用,因为从未创建目标文件夹./cfgrib
吗?
有人遇到这个问题吗?任何帮助表示赞赏。