【问题标题】:web2py python - ImportError cannot import nameweb2py python - ImportError 无法导入名称
【发布时间】:2016-12-24 18:12:53
【问题描述】:

我不断收到此错误:<type 'exceptions.ImportError'> cannot import name get_cert_infos。 我很确定我正确导入了所有内容。有问题的文件是participant.py 并且有:

from datetime import date

from widgets import SelectOrAdd, LabelSortedOptionsWidget, DynamicSelect, \
        AutocompleteReferenceWidget
from communication import handle_notification, send_email
from utility import create_temp_password, hash_password

from export import get_cert_infos, build_certificate

我有exports.pyget_cert_infosbuild_certificate 方法确实存在其中。我不明白问题是什么。

我查看了其他几篇关于此的帖子,他们似乎都在说这很可能是循环导入问题

我已经安装并更新了exportexport==0.1.2

ImportError: Cannot import name X

【问题讨论】:

  • export.py 还是exports.py?那个模块到底是什么?我们能看到吗?

标签: python python-2.7 import web2py importerror


【解决方案1】:

尝试仔细检查拼写,我知道这很愚蠢,但它确实发生了。

如果不是这样,请尝试在导出中编写此方法

def hello_world():
    print 'hello world'

然后

import export

export.hello_world()

如果可行,则方法本身可能有问题,如果不是,我认为名称 export 已保留并导致冲突(我的代码编辑器并未将其标记为保留)。

是否只需要导入这两种方法?或者你能像 hello_world 一样导入整个模块并使用所需的方法吗?这会给你带来麻烦吗?如果你删除get_cert_infos build_certificate 会给你带来麻烦吗?

【讨论】:

  • 谢谢。原来是保留字export 引起了冲突。我正在导入导出并且有一个名为 export.py 的文件...导出覆盖了我的 export.py,因此没有我需要的方法。我运行了pip uninstall export,因为我实际上并不需要它,它解决了我的问题。我必须重命名该文件以避免将来发生冲突。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-10-02
  • 2014-09-27
  • 2020-04-09
  • 2012-11-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多