没有名为x的模块

没有名为x的模块

本文介绍了相对导入-ModuleNotFoundError:没有名为x的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次真正坐下来尝试python 3,但似乎失败了.我有以下两个文件:

This is the first time I've really sat down and tried python 3, and seem to be failing miserably. I have the following two files:

  1. test.py
  2. config.py

config.py中定义了一些函数以及一些变量.我将其简化为以下内容:

config.py has a few functions defined in it as well as a few variables. I've stripped it down to the following:

但是,出现以下错误:

ModuleNotFoundError: No module named 'config'

我知道py3约定是使用绝对导入:

I'm aware that the py3 convention is to use absolute imports:

from . import config

但是,这会导致以下错误:

However, this leads to the following error:

ImportError: cannot import name 'config'

因此,我对这里的操作一无所知...任何帮助将不胜感激. :)

So I'm at a loss as to what to do here... Any help is greatly appreciated. :)

推荐答案

正如原始帖子的注释中所述,这似乎是我出于任何原因使用的python解释器的问题,而不是什么问题python脚本.我从WinPython包切换到了python.org上的官方python 3.6,它工作得很好.谢谢大家的帮助:)

As was stated in the comments to the original post, this seemed to be an issue with the python interpreter I was using for whatever reason, and not something wrong with the python scripts. I switched over from the WinPython bundle to the official python 3.6 from python.org and it worked just fine. thanks for the help everyone :)

这篇关于相对导入-ModuleNotFoundError:没有名为x的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 18:08