Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing error #28

Open
BOXEL-REBOUND opened this issue Aug 2, 2022 · 5 comments
Open

Importing error #28

BOXEL-REBOUND opened this issue Aug 2, 2022 · 5 comments

Comments

@BOXEL-REBOUND
Copy link

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
Copy link

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
Copy link

sq3kk commented Nov 23, 2022

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

@nigamanthsrivatsan
Copy link
Contributor

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
Copy link

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
Copy link

bigbuny commented Jun 5, 2024

Aight, can we do a pull request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants