首页 > 解决方案 > Python - 'No module named..' 使用 Visual Studio 便携版

问题描述

我正在使用 Visual Studio Portable 创建 TCP 模拟器 - 在执行代码时使用 client.py、state.py 和 server.py 会产生错误:ModuleNotFoundError: No module named 'State' - 任何人都可以帮忙吗?

这是存在错误的行 'from State import *'

这就是终端产生的:

Traceback(最近一次通话最后一次):文件“c:/Users/Chloe/Documents/Computer Science Uni Work/Final Year/Computer Networks/Coursework 2/New/client.py”,第 1 行,来自状态导入 * ModuleNotFoundError:没有名为“状态”的模块

以下是 state.py 中包含的内容

    class State:
    state = None #abstract class
    CurrentContext = None
    def __init__(self, Context):
        self.CurrentContext.Context = Context

class StateContext:
    stateIndex = 0
    CurrentState = None
    availableStates = []

    def setState(self, newstate):
        self.CurrentState = self.availableStates[newstate]
        self.stateIndex = newstate

    def getStateIndex(self):
        return self.stateIndex

非常感谢

标签: python

解决方案


推荐阅读