PolyMarsDev / Flappuccino

A Pygame game made in 48 hours
354 stars 127 forks source link

Importing error #28

Open BOXEL-REBOUND opened 2 years ago

BOXEL-REBOUND commented 2 years ago

When I run it, the terminal says Import Error. Here's the total error:

Traceback (most recent call last): File "c:\Users\dacpu\OneDrive\Desktop\Flappuccino\main.py", line 5, in from .player import Player ImportError: attempted relative import with no known parent package

I have every file, and it is not just this import, it is all of them.

justinlangley3 commented 2 years ago

The imports are not setup correctly in this project.

It tends poor usage in Python to use relative imports unless you're adding them to the __init__.py file of a sub-package to resolve broken imports. Otherwise you'll probably end up with that import error or the infamous circular import error.

Please Reference: PEP 8 - Imports

In the example @BOXEL-REBOUND provides of Line 5 it's the incorrect way to import: from .player import Player

The imports from other project files should look like this (following PEP 8 style conventions):

from background import Background
from bean import Bean
from button import Button
from player import Player
from utils import clamp, check_collisions

Another thing to note is there are other imports in this project that break PEP 8 style conventions. For example (incorrect):

import colorsys, math, random, sys, time

Following PEP 8 style conventions (correct):

import colorsys
import math
import random
import sys
import time

The rule is one import per line, and the only exception is multiple imports from a package or sub-package, as seen above:

from utils import clamp, check_collisions

One more PEP 8 violation I saw a lot of in this project follows up on the last example: In the utils package, there is a function named checkCollisions, but it should be named check_collisions to follow python's naming convention guidelines. In that same file there is another violation where the reserved keywords min, max are used as parameters to the clamp function.

Please Reference: PEP 8 - Naming Conventions

sq3kk commented 1 year ago

I guess you can take the player module and put it into the main.py file MANUALLY. That's what I did.

nigamanthsrivatsan commented 1 year ago

I guess you can take the player module and put it into the main.py file MANUALLY. That's what I did.

You can, but that isn't the better way of solving the issue. When I made my last contribution to this repository, Python's update wasn't released so to import from a package you had to state that the file you're importing is relative.

You have to follow the new Python update by removing all the .'s, they indicate relativity but only in "modules".

CaptainChicky commented 1 year ago

The imports are not setup correctly in this project.

Please Reference: PEP 8 - Imports

I mean, this game was literally made at a game jam, with 2 days time, so it makes sense to not strictly follow import guidelines lol. During coding jams/thons whatever you're usually aiming to write working code, not maintainable code.

bigbuny commented 3 months ago

Aight, can we do a pull request?