如何解决python中的theano循环导入问题?

问题描述 投票:0回答:1

我尝试在我的 jupyternotebook 中运行 2019 年的一些代码。我遇到错误,不知道如何解决:



----> 8 import theano.tensor as T

...


File ~/my-jupyter-env/lib/python3.11/site-packages/theano/__init__.py:124
    120 from theano.misc.safe_asarray import _asarray
    122 from theano.printing import pprint, pp
--> 124 from theano.scan_module import (scan, map, reduce, foldl, foldr, clone,
    125                                 scan_checkpoints)
    127 from theano.updates import OrderedUpdates
    129 # scan_module import above initializes tensor and scalar making these imports
    130 # redundant
    131 
   (...)
    136 
    137 # import sparse

File ~/my-jupyter-env/lib/python3.11/site-packages/theano/scan_module/__init__.py:41
     38 __copyright__ = "(c) 2010, Universite de Montreal"
     39 __contact__ = "Razvan Pascanu <r.pascanu@gmail>"
---> 41 from theano.scan_module import scan_opt
     42 from theano.scan_module.scan import scan
     43 from theano.scan_module.scan_checkpoints import scan_checkpoints

File ~/my-jupyter-env/lib/python3.11/site-packages/theano/scan_module/scan_opt.py:60
     57 import numpy as np
     59 import theano
---> 60 from theano import tensor, scalar
     61 from theano.tensor import opt, get_scalar_constant_value, Alloc, AllocEmpty
     62 from theano import gof

File ~/my-jupyter-env/lib/python3.11/site-packages/theano/tensor/__init__.py:8
      4 __docformat__ = "restructuredtext en"
      6 import warnings
----> 8 from theano.tensor.basic import *
      9 from theano.tensor.subtensor import *
     10 from theano.tensor.type_other import *

File ~/my-jupyter-env/lib/python3.11/site-packages/theano/tensor/basic.py:20
     17 from theano.gof import Apply, Constant, Op, Variable, ParamsType
     18 from theano.gof.type import Generic
---> 20 from theano.scalar import int32 as int32_t
     21 from theano.tensor import elemwise
     22 from theano.tensor.var import (AsTensorError, TensorVariable,
     23                                TensorConstant, TensorConstantSignature,
     24                                _tensor_py_operators)

File ~/my-jupyter-env/lib/python3.11/site-packages/theano/scalar/__init__.py:3
      1 from __future__ import absolute_import, print_function, division
----> 3 from .basic import *
      5 from .basic_scipy import *

File ~/my-jupyter-env/lib/python3.11/site-packages/theano/scalar/basic.py:657
    654         return shape_info
    656 # Register C code for ViewOp on Scalars.
--> 657 theano.compile.register_view_op_c_code(
    658     Scalar,
    659     """
    660     %(oname)s = %(iname)s;
    661     """,
    662     1)
    665 bool = get_scalar_type('bool')
    666 int8 = get_scalar_type('int8')

AttributeError: partially initialized module 'theano' has no attribute 'compile' (most likely due to a circular import)

在 readme.md 中据说它需要 Theano (1.0.0) 和 numpy (1.13.3)。 我应该将我的版本降级到这些版本才能运行它吗?我尝试过,但没有帮助。我听说 theano 现在已经死了,我看到很多错误,例如 theano 使用“collections”库中的“MlatbleMaps”,但现在由于一些更新,它应该是“collections.abc”。所以我尝试更改我的 theano 源代码中的这个集合错误,但现在我没有收到此错误。但我有错误,我不知道如何解决我在这里显示的问题。 那么我应该在代码或安装中更改哪些内容才能消除此错误?或者也许我应该做一些不同的事情来安全地运行theano,在2023年?我知道我可以使用tensorflow作为例子,但是这段代码很长,我不想重写它。

python jupyter-notebook python-import importerror theano
1个回答
0
投票

查看 PyPi 看起来他们更新了库以支持 Python 3.9,但您正在运行 Python 3.11,这可能会导致问题。

此外,如果您从他们的存储库中检查自述文件,确实会说:

MILA 将停止开发 Theano:https://groups.google.com/d/msg/theano-users/7Poq8BZutbY/rNCIfvAEAwAJ [2017 年 9 月 28 日]

您有两个选择:

  • 推荐:Theano 被分叉成一个名为 Aesara 的新项目,该项目得到积极维护并支持 Python 3.11。您必须更新 Jupyternotebook 代码才能使用 Aesara。
  • 不推荐:安装Python 3.9,安装依赖项并尝试运行jupyternotebook。不建议这样做,因为您必须安装旧版本的 Python,并且您将使用停止获取更新的旧项目 (Theano)。
© www.soinside.com 2019 - 2024. All rights reserved.