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

Import issue #2

Open
AndreyeuIvan opened this issue Nov 6, 2021 · 10 comments
Open

Import issue #2

AndreyeuIvan opened this issue Nov 6, 2021 · 10 comments

Comments

@AndreyeuIvan
Copy link

While issue python 3.10. Get an issue of import.
"from ..database import Base" - attempted relative import beyond top-level package
Also router get an issue.

@tonyhart7
Copy link

same issue on python 3.10

@tonyhart7
Copy link

have anyone fix this issue ?

@tonyhart7
Copy link

@Sanjeev-Thiyagarajan can you help me

@AndreyeuIvan
Copy link
Author

AndreyeuIvan commented Nov 16, 2021

Hi, Tony.

Please try to improve repository. For me worked like this:
src/
------ main.py
------ alembic
------ venv
------ app/
----------- bd.py
----------- conf.py
----------- routers/
---------------- user.py
---------------- my_service.py

@tonyhart7
Copy link

Hi, Tony.

Please try to improve repository. For me worked like this: src/ ------ main.py ------ alembic ------ venv ------ app/ ----------- bd.py ----------- conf.py ----------- routers/ ---------------- user.py ---------------- my_service.py

but the issue is not my folder structure

I can access it on class and run the method in it
last time I followed tutorial and on the video, the instructor import a models despite 'function' and child import not contain 'right' models type

Idk why that work on video despite I tried the same thing line by line in my code
I not facing this issue on other language and framework (strong and strict type)
so maybe this is a natural python behaviour that I must get use to

@nitingang9981
Copy link

check file name. For me I missed 't' in conftest.py. I was stuck on that for 2 hours.

@phillus33
Copy link

Had the same problem, here's my solution:

  1. Change from .database import Base to from database import Base (omit the leading dot)
  2. Similarly, change from . import models to import models since models is supposedly in the same dir as main

FYI

@Deltronzero3018
Copy link

I'm running into the same issue @tonyhart7 is, any answers?

@Deltronzero3018
Copy link

I found the answer
import sys
sys.path.insert(0, './app')

@pizza-lazor
Copy link

i had to remove any . or from . to get this to work im using python 3.10.6

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