简体   繁体   English

从同一目录中的代码导入函数时未解析的导入“GUI.py”Python(未解析导入)

[英]unresolved import 'GUI.py' Python(unresolved-import) when importing functions from code in same directory

I'm trying to call functions from separate python files within the same folder directory but receiving the following error within VSCode.我正在尝试从同一文件夹目录中的单独 python 文件调用函数,但在 VSCode 中收到以下错误。

unresolved import 'IXL_main.py'Python(unresolved-import)

When trying to run the code directly I get the following error:尝试直接运行代码时,出现以下错误:

Traceback (most recent call last):
  File "TMS_main.py", line 30, in <module>
    from TMS_threading import globalStopAllTrains
ImportError: cannot import name 'globalStopAllTrains' from 'TMS_threading' (C:\Users\....\TMS_threading.py)

I've tried the following:我尝试了以下方法:

  • Refresh VSCode刷新 VSCode
  • Refresh & Check Python Interpreter刷新并检查 Python 解释器
  • Reinstalling VSCode重新安装 VSCode
  • Re-Typing Import Modules & Files重新输入导入模块和文件
  • Creating and adding .env file and path to settings.json创建和添加 .env 文件和 settings.json 的路径

I need more information.我需要更多信息。

So you have two files in the same folder.所以你在同一个文件夹中有两个文件。 You run the first file with Python ( python first_file.py ).您使用 Python ( python first_file.py ) 运行第一个文件。 This first_file imports the second one like this: from second_file import your_function .这个first_file像这样from second_file import your_function第二个: from second_file import your_function Then, still in your first file, the command your_function(arguments) raises this error ?然后,仍然在您的第一个文件中,命令your_function(arguments)会引发此错误?

在设置中搜索“绝地”以替换 Microsoft Python 分析引擎

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

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