【问题标题】:I'm getting the following Import Error when importing the sutime module - what does it mean?导入 sutime 模块时出现以下导入错误 - 这是什么意思?
【发布时间】:2020-01-15 00:30:30
【问题描述】:

我收到此错误:

ImportError: cannot import name 'SUTime' from partially initialized module 'sutime' (most likely due to a circular import)

将 sutime 模块导入为:

from sutime import SUTime

按照 sutime GitHub 示例中的建议:https://github.com/FraBle/python-sutime

上下文:sutime 是一个 Python 库,用于从自然语言输入中解析日期/时间,由斯坦福 CoreNLP 的出色团队开发。

注意:我也已经运行了 pre-req 安装:

>> pip install setuptools_scm jpype1 # install pre-reqs
>> pip install sutime
>> # use package pom.xml to install all Java dependencies via Maven into ./jars
>> mvn dependency:copy-dependencies -DoutputDirectory=./jars

【问题讨论】:

    标签: python python-3.x nlp stanford-nlp sutime


    【解决方案1】:

    循环导入最有可能导致您的错误是不正确的。失败、不完整或以某种方式奇怪的安装更有可能。试试这个:

    pip uninstall sutime
    pip uninstall jpype1
    pip uninstall setuptools_scm
    pip3 install setuptools_scm jpype1  # note: pip3
    pip3 install sutime
    

    然后,在python-sutime 目录中,输入以下命令:

    ./test.sh
    

    它应该输出很多日志行,最后一行应该是这样的:

    ======================== 5 passed, 2 warnings in 13.06s ========================
    

    在同一目录中,您可以从自述文件的示例部分输入并运行 Python 脚本。它应该在报告的输出之前输出许多日志行。可能有一种方法可以避免这种情况,但无论如何它只会发生一次,即脚本启动时。

    【讨论】:

    • 我已经完成了上述步骤,但得到了同样的错误:(我输入了命令并得到了这个返回:zsh: no such file or directory: ./test.sh
    • Ohhhhhhhhh 我发现了问题所在。我已将我的脚本命名为 sutime.py,这绝对是问题所在。现在,我只收到以下错误(进度!):/Library/Frameworks/Python.framework/Versions/3.8/bin/python3: can't open file 'sutime.py': [Errno 2] No such file or directory
    • 你什么时候做什么,具体做什么,在什么目录下?
    • 从我的桌面(我的脚本所在的文件夹)运行我的 Python 脚本,顶部是 sutime import SUTime
    • 尝试将您的脚本移动(或复制)到 python-sutime 项目的 checkout 目录(应该称为python-sutime),然后从那里运行它
    【解决方案2】:
    1. 克隆 git 存储库。 -

      !git 克隆https://github.com/FraBle/python-sutime.git

    2. 转到克隆仓库中的 python-sutime/sutime。有一个 pom.xml 文件。打开终端并发出以下命令。

      mvn 依赖:copy-dependencies -DoutputDirectory=./jars -P 英语

    3. 现在您可以简单地从克隆的 repo 文件夹中的 sutime.py 脚本导入 sutime。

    4. 如果你想在任何地方使用 sutime,安装 sutime 使用...

      pip 安装 sutime

    并将 /usr/local/lib/python3.6/dist-packages/sutime 文件夹替换为您在第 2 步之后获得的 sutime 文件夹。

    【讨论】:

      猜你喜欢
      • 2016-09-28
      • 1970-01-01
      • 2021-10-24
      • 1970-01-01
      • 2021-08-06
      • 2022-11-30
      • 2023-03-20
      • 2018-05-14
      • 1970-01-01
      相关资源
      最近更新 更多