J
J
Jekson2020-07-15 13:45:18
Python
Jekson, 2020-07-15 13:45:18

How to import from a module?

Project Structure

├── db.py
├── __init__.py
├── main.py
├── migrations
│   ├── env.py
│   ├── __pycache__
│   │   └── env.cpython-37.pyc
│   ├── README
│   ├── script.py.mako
│   └── versions


In the env.py file, you need to import 2 variables from db.py

tried in different ways
from ..db import DATABASE_URL, metadata
returns
ImportError: attempted relative import with no known parent package


if so,
from db import DATABASE_URL, metadata
it returns
ModuleNotFoundError: No module named 'db'

How to import correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-07-15
@bacon

Probably all the same from название_проекта.db ..., or whatever you have in your pythonpath, or where the script is launched from.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question