【问题标题】:ModuleNotFoundError: No module named 'ecommerce'ModuleNotFoundError:没有名为“电子商务”的模块
【发布时间】:2021-04-01 00:37:36
【问题描述】:

我是 python 新手,我无法理解为什么我会遇到标题错误。

这是我的项目结构:

这就是我在 shipping.py 模块中的内容:

def calc_shipping():
    print('Calculating shipping...')

所以当我这样做时 -> from ecommerce.shipping import calc_shipping

并且想使用 calc_shipping()

我收到错误 ->

Traceback (most recent call last):
  File "/Users/burakhanaksoy/gitHub/Python/PythonStudy/bman/basics/modules/app.py", line 9, in <module>
    from ecommerce.shipping import calc_shipping
ModuleNotFoundError: No module named 'ecommerce'

感谢任何帮助。

最好的,

PS:我在 PyCharm 中也遇到了同样的错误,实际上在 PyCharm 中,它甚至不会在我输入时自动填充“电子商务”或“ecommerce.shipping” from ecommerce.shipping import calc_shipping

【问题讨论】:

  • 尝试 basics.ecommerce.shipping 或将“模块”更改为 python 模块?
  • 感谢@Neeraj 的回答,现在可以了。如果您回答问题,我可以投票。
  • 很高兴我能帮上忙 :)

标签: python pycharm


【解决方案1】:

在这种情况下,请务必检查以下事项:

  1. 如果模块有 init,换句话说,如果它是一个 python 模块
  2. 检查它是否可以从父目录访问,在这个例子中是基础。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-22
    • 2019-03-28
    • 2022-01-07
    • 2017-12-14
    • 2020-12-10
    • 2021-09-02
    • 2020-10-10
    相关资源
    最近更新 更多