ModuleNotFoundError:没有名为“theano.tensor.shared_randomstreams”的模块
Posted
技术标签:
【中文标题】ModuleNotFoundError:没有名为“theano.tensor.shared_randomstreams”的模块【英文标题】:ModuleNotFoundError: No module named 'theano.tensor.shared_randomstreams' 【发布时间】:2020-06-30 05:55:43 【问题描述】:我试图使用 pyinstaller 将我的 python 代码转换为可执行文件。我正在使用 pyinstaller=3.5 和 setuptools=41.2.0 的 ubuntu 18.04。当我运行可执行文件时,我收到以下错误:
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】:-
打开终端
输入
sudo pip3 install theano
如果它无法识别命令pip3
,则通过执行this 来检查是否安装了pip,假设它已安装。如果不是输入sudo apt-get install pip3
【讨论】:
我尝试使用此命令卸载和安装 theano。安装成功。但是,我仍然遇到同样的错误。【参考方案2】:重新创建以下内容:
- 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
。
【讨论】:
我应该将其运行为:pyinstaller --onefile \ ----addtional-hooks-dir=hooks\ code.files.py 吗?pyinstaller --onefile --additional-hook-dir=hooks yourscript.py
应该可以工作以上是关于ModuleNotFoundError:没有名为“theano.tensor.shared_randomstreams”的模块的主要内容,如果未能解决你的问题,请参考以下文章
ModuleNotFoundError:没有名为“dataviz”的模块
ModuleNotFoundError:没有名为“numpy”的模块
错误:ModuleNotFoundError:没有名为“图像”的模块
ModuleNotFoundError:没有名为“knox”的模块