【问题标题】:ImportError: cannot import name 'constants'ImportError:无法导入名称“常量”
【发布时间】:2018-10-22 09:43:30
【问题描述】:

我需要导入常量库,但它不起作用...

import spacy
import pandas
import textacy
import pandas as pd
from pandas import Series
from . import constants

错误:

ImportError                               Traceback (most recent call last)
<ipython-input-49-df52595371dd> in <module>()
  4 import pandas as pd
  5 from pandas import Series
----> 6 from . import constants

ImportError: cannot import name 'constants'

我在 Windows 10 上使用 anaconda 3 并尝试使用 conda 安装此库:

conda install -c auto constants

但是还是不行……

【问题讨论】:

  • 你为什么要从 .导入而不是仅仅导入?
  • 也不能使用导入常量...同样的错误
  • 如果你在终端中输入“conda list”,那里有常量吗?
  • 不,它不存在。没想到……
  • 这意味着您的安装失败或者您处于不同的 conda python 环境中。

标签: python anaconda constants textacy


【解决方案1】:
from . import constants

在当前目录中导入一个名为 constants 的 python 文件。

我怀疑你是否将它安装在你的目录中?

那么import constants

。意思是查看当前目录我相信

【讨论】:

    【解决方案2】:

    在最后一行不应该使用from。只需输入:

    import constants
    

    这应该可以解决问题。

    【讨论】:

      猜你喜欢
      • 2015-12-15
      • 1970-01-01
      • 2018-02-14
      • 2016-03-31
      • 2014-10-10
      • 2014-09-20
      • 2014-08-28
      • 2014-06-10
      • 2016-05-16
      相关资源
      最近更新 更多