ModuleNotFoundError: No module named 'theano.tensor.shared_randomstreams'

ModuleNotFoundError: No module named 'theano.tensor.shared_randomstreams'

我试图使用 pyinstaller 将我的 python 代码转换为可执行文件。我正在使用 ubuntu 18.04,pyinstaller=3.5 和 setuptools=41.2.0。当我 运行 可执行文件时,出现以下错误:

Using Theano backend.
Traceback (most recent call last):
File "main_test.py", line 25, in <module>
File "/home/g2-test/anaconda3/envs/ashna/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "code.py", line 2, in <module>
File "/home/g2-test/anaconda3/envs/ashna/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages/keras/__init__.py", line 3, in <module>
File "/home/g2-test/anaconda3/envs/ashna/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages/keras/utils/__init__.py", line 6, in <module>
File "/home/g2-test/anaconda3/envs/ashna/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages/keras/utils/conv_utils.py", line 9, in <module>
File "/home/g2-test/anaconda3/envs/ashna/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages/keras/backend/__init__.py", line 1, in <module>
File "/home/g2-test/anaconda3/envs/ashna/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages/keras/backend/load_backend.py", line 87, in <module>
File "/home/g2-test/anaconda3/envs/ashna/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages/keras/backend/theano_backend.py", line 7, in <module>
File "/home/g2-test/anaconda3/envs/ashna/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages/theano/__init__.py", line 247, in <module>
ModuleNotFoundError: No module named 'theano.tensor.shared_randomstreams'
[6919] Failed to execute script main_test

我用过

pyinstaller --onefile main_test.py

生成可执行文件。我曾使用过 keras,但在 运行 宁可执行文件时,它显示使用 theano 后端。 有人可以帮我解决这个问题吗?

  1. 打开终端
  2. 输入sudo pip3 install theano

如果它无法识别命令 pip3,则通过执行 this 检查 pip 是否已安装,假设已安装。如果不是类型 sudo apt-get install pip3

重新创建以下内容:

- your.code.files.py
- hooks
  - hook-theano.py

hook-theano.py中:

from PyInstaller.utils.hooks import collect_all

datas, binaries, hiddenimports = collect_all('theano')

然后使用额外选项 --addtional-hooks-dir=hooks 进行构建。

如果您遇到更多模块未找到错误的其他问题(假设您找不到 mymod.pkg.func),请在 hooks 下创建一个名为 hook-mymod.py 的新文件。