我正在尝试导入这样的 python 文件
import tiny
tiny.create_window('test')
里面很小的是
from tkinter import *
def create_window (Name='Window'):
window = Tk()
window.title(Name)
return window
但是当我运行它时会出错
Traceback (most recent call last):
File "C:\Users\Harry\Documents\python files\tests\test4.py", line 1, in <module>
import tiny
ModuleNotFoundError: No module named 'tiny'
您的“tiny.py”文件是否与您的主“test4.py”文件在同一目录中?在这种情况下,您的 tiny.py 和 test4.py 文件都在
C:\Users\Harry\Documents\python files\tests\
Python 解释器不知道要搜索哪些目录才能找到文件。因此,您的两个文件必须位于同一位置,以便解释器知道在哪里可以找到它们。或者,您可以查找一些有关创建模块和包的教程,但这更高级一些。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句