in migrations/env.py file I am trying to import from database import *
but it shows no module name database
I tried from ..database imprt * and adding file in pythonpath also but no luck :(
-
In which directory are you invoking the interpreter?deets– deets2018-12-10 16:30:25 +00:00Commented Dec 10, 2018 at 16:30
-
Wich python version are you using?Rodrigo López– Rodrigo López2018-12-10 16:39:22 +00:00Commented Dec 10, 2018 at 16:39
-
@RodrigoLópez I am using python 3.6Sanjay– Sanjay2018-12-11 05:10:39 +00:00Commented Dec 11, 2018 at 5:10
2 Answers
Your directory structure looks a bit suspicious to me. The alembic.ini shouldn't normally be part of the package (and setuptools won't by default pick it up when packaging). I think this would better be placed into the project-root.
Something like this would be more standard:
├── alembic.ini
├── migrations
│ ├── env.py
│ ├── script.py.mako
│ └── versions
│ └── ...
├── package_name
│ └── database
│ ├── __init__.py
│ └── ...
│ └── models
│ └── __init__.py
│ └── ...
├── README.md
└── setup.py
└── ...
Now, this alone would not make database available from env.py. For this to work you have to somehow make your package discoverable. Usually this would be done by installing package_name into some virtualenv. In that environment you could then use from package_name.database import * in your env.py.
5 Comments
__init__.pymodels does, but database does notMigrations needs to know where to import from, they either belong to the same package:
A:
migrations
database
init.py
And then in migrations:
from A.database.whatever import whatever else
Or you install them as packages separatedly inside your virtualenv: And then each of them is dependent on the other, but because they are installed they can be invoked:
database/setup.py migrations/setup.py
Then both are installed and migrations/env.py can call the installed package database
