FileNotFoundError: [Errno 2] No such file or directory ,,,/theano/gpuarray/c_code/blockgemv.c

FileNotFoundError: [Errno 2] No such file or directory ,,,/theano/gpuarray/c_code/blockgemv.c

我写了这段代码:

import theano
print('hello')

然后运行 pyinstaller 制作exe文件。进程完成,但是当我 运行 exe 文件时,出现这个错误:

Traceback (most recent call last):
  File "tk_torch_test.py", line 11, in <module>
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "C:\Users\deep1\anaconda3\envs\MultiFace\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 491, in exec_module
    exec(bytecode, module.__dict__)
  File "theano\__init__.py", line 156, in <module>
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "C:\Users\deep1\anaconda3\envs\MultiFace\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 491, in exec_module
    exec(bytecode, module.__dict__)
  File "theano\gpuarray\__init__.py", line 33, in <module>
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "C:\Users\deep1\anaconda3\envs\MultiFace\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 491, in exec_module
    exec(bytecode, module.__dict__)
  File "theano\gpuarray\fft.py", line 14, in <module>
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "C:\Users\deep1\anaconda3\envs\MultiFace\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 491, in exec_module
    exec(bytecode, module.__dict__)
  File "theano\gpuarray\opt.py", line 64, in <module>
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "C:\Users\deep1\anaconda3\envs\MultiFace\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 491, in exec_module
    exec(bytecode, module.__dict__)
  File "theano\gpuarray\blocksparse.py", line 86, in <module>
  File "theano\gpuarray\blocksparse.py", line 32, in __init__
  File "theano\gof\op.py", line 1308, in __init__
  File "theano\gof\op.py", line 1331, in load_c_code
FileNotFoundError: [Errno 2] No such file or directory: 'D:\Deep1\Projects\multifacetracker_exe\dist\VideoAnonymizer\theano\gpuarray\c_code\blockgemv.c'

感谢您的帮助

如果theano安装在Lib\site-packages\theano,你需要创建一个hook-theano.py文件,内容如下:

from PyInstaller.utils.hooks import get_package_paths
datas = [(get_package_paths('theano')[1],"theano"),]

并将此文件复制到您的 PyInstaller 文件夹中:

Lib\site-packages\PyInstaller\hooks

当你运行pyinstaller时,你需要用-p选项添加mxnet的路径:

pyinstaller myApp.py -p <your-path-to-this-point>\Lib\site-packages

它将整个 mxnet 文件夹复制到您的 dist 输出文件夹中。