简体   繁体   English

导入另一个.py文件会引发错误

[英]Importing another .py file throwing an error

I'm trying to import a .py file named 'main' within the same directory as my main file. 我正在尝试在与主文件相同的目录中导入名为“ main”的.py文件。

from .settings import *

When I run it I get this error 当我运行它时,出现此错误

    Traceback (most recent call last):
      File "C:/Users/user_1/Desktop/Projects/program/main.py", line 5, in <module>
        from .settings import *
    ModuleNotFoundError: No module named '__main__.settings'; '__main__' is not a package

Why isn't this working and how do I fix it? 为什么这不起作用,我该如何解决?

You need to have the package in library folder of python. 您需要将包放在python的库文件夹中。 For me keeping any module inside this directory works 对我而言,将任何模块保留在此目录下均有效

C:\Program Files\Anaconda3\Lib\site-packages

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM