0

I have structure project python

MyProject
+Classes
    -stage_competition.py
main.py

Executing Python (main.py) - Show error "ModuleNotFoundError("No module named 'Classes'",)"

I tried import direct, but is not working too, always showing same error

from Classes.stage_competition import Stage_competition

item = Stage_competition("field1", "field2", "field3" , "field4")


Create class Stage_competition

class Stage_competition(object):
    """description of class"""

    def __init__(self, type_competition, datalake, competition ,hour):
        self.type_competition = type_competition
        self.datalake = datalake
        self.competition = competition
        self.hour = hour

    def settype_competition(self, type_competition):
        self.type_competition = type_competition

    def setdatalake(self, datalake):
        self.datalake = datalake

    def getcompetition(self):
        return self.competition

    def gethour(self):
        return self.hour
2
  • Which python version are you using? Commented Sep 27, 2018 at 13:45
  • version Python 3.7 Commented Sep 27, 2018 at 14:11

1 Answer 1

1

If the Classes is in the same folder as main.py, you should import it this way (notice the dot before Classes):

from .Classes.stage_competition import Stage_competition

Alternatively, you could add directory to Classes to PYTHONPATH, which allows you to import Classes from anywhere.

Sign up to request clarification or add additional context in comments.

3 Comments

main.py is in the other folder project root.
then you should import using relative path to Classes, or add Classes to path to import
I got it, is was folder configuration, it was not as a package. Tks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.