首页 > 解决方案 > Cannot import classes.(something) in Pycharm when that 'something' has already been defined

问题描述

import classes.game import bcolors, Person

I have been trying to import game.py on my other file main.py but for some reason Pycharm shows this as unresolved error or something like that. What do I do?

标签: pythonpycharm

解决方案


If you type from classes.game import bcolors, Person, python will look for a file called classes.game.py, which doesn't exist.

Instead you should do

from game import bcolors, Person

as you're trying to import from the module 'game.py'.


推荐阅读