我正在尝试使用oct2py在简短的python脚本中重用一些八度的代码(在1 .m文件中)。 python脚本可从cmd控制台正常运行。我什至可以使用pyinstaller将其打包为exe文件(没有错误,只有几个警告),但是当我运行它时,可执行文件会抛出此错误并退出:
---
C:\Users\Jason\Desktop\Oct2Py test>readFolder.exe
Traceback (most recent call last):
File "readFolder.py", line 2, in <module>
from oct2py import octave
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:\python37\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\oct2py\__init__.py", line 26, 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:\python37\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\oct2py\core.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:\python37\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\octave_kernel\kernel.py", line 49, in <module>
File "site-packages\octave_kernel\kernel.py", line 54, in OctaveKernel
File "site-packages\octave_kernel\kernel.py", line 43, in get_kernel_json
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\toshiba\\AppData\\Local\\Temp\\_MEI94962\\octave_kernel\\kernel.json
[5220] Failed to execute script readFolder
我已经安装了最新版本的python(3.7.1),oct2py(4.0.6),pyinstaller等
感觉就像我在丢失某物或不在此处某处连接某物一样,有人可以帮我解决这个问题吗? 谢谢!
答案 0 :(得分:1)
我遇到了同样的问题,正如DNR所说,我解决了设置OCTAVE_KERNEL_JSON变量的问题。为此:
示例:
a = Analysis(...
datas=[ ('/home/user/miniconda3/envs/env/lib/python3.8/site-packages/octave_kernel/kernel.json', 'octave_kernel') ],
...
)
if getattr(sys, 'frozen', False):
application_path = sys._MEIPASS
os.environ["OCTAVE_KERNEL_JSON"] = os.path.join(application_path, 'octave_kernel/kernel.json')