Alembic: No module named 'app'

See original GitHub issue

With a fresh clone of this project from cookiecutter, alembic does not run:

$ alembic upgrade head
Traceback (most recent call last):
  File "/Users/austin/.virtualenvs/ccfast/bin/alembic", line 8, in <module>
    sys.exit(main())
  File "/Users/austin/.virtualenvs/ccfast/lib/python3.9/site-packages/alembic/config.py", line 581, in main
    CommandLine(prog=prog).main(argv=argv)
  File "/Users/austin/.virtualenvs/ccfast/lib/python3.9/site-packages/alembic/config.py", line 575, in main
    self.run_cmd(cfg, options)
  File "/Users/austin/.virtualenvs/ccfast/lib/python3.9/site-packages/alembic/config.py", line 552, in run_cmd
    fn(
  File "/Users/austin/.virtualenvs/ccfast/lib/python3.9/site-packages/alembic/command.py", line 298, in upgrade
    script.run_env()
  File "/Users/austin/.virtualenvs/ccfast/lib/python3.9/site-packages/alembic/script/base.py", line 489, in run_env
    util.load_python_file(self.dir, "env.py")
  File "/Users/austin/.virtualenvs/ccfast/lib/python3.9/site-packages/alembic/util/pyfiles.py", line 98, in load_python_file
    module = load_module_py(module_id, path)
  File "/Users/austin/.virtualenvs/ccfast/lib/python3.9/site-packages/alembic/util/compat.py", line 184, in load_module_py
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 790, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "alembic/env.py", line 23, in <module>
    from app.db.base import Base  # noqa
ModuleNotFoundError: No module named 'app'

Looking at the way the source code is organized, I’m not sure it can work unless PYTHONPATH is modified or the alembic folder is moved. Can anyone shed some light on this?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
tiangolocommented, Dec 27, 2020

Thanks for the help here everyone! 👏 🙇

Thanks for reporting back and closing the issue 👍

0reactions
Fingelcommented, Dec 2, 2020

I see, it looks like this project is meant to be developed while being served from within a docker container.

I’ve found that workflow to be more inconvenient than it is worth, and would prefer personally to just work with the source tree directly. I’ll close this since it looks like it was never actually meant to work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Importing app when using Alembic raises ImportError
alembic just tries to load your env.py source code. It's not in your package, so it can't access your app module.
Read more >
[QUESTION] Postgresql template migration error #223 - GitHub
Hi, I am getting an issue when I want to use Alembic for migration. ... app.db.base import Base ModuleNotFoundError: No module named 'app'....
Read more >
$PYTHONPATH setup for running Alembic? - Google Groups
When using Alembic autogenerate command, we need to add a new module (mymodule) to $PYTHONPATH, and then configure ... ImportError: No module named...
Read more >
ModuleNotFoundError: No module named 'myapp' alembic
Answers related to “ModuleNotFoundError: No module named 'myapp' alembic”. ModuleNotFoundError: No module named · no module named · python no module named.
Read more >
Configuration — Alembic 1.9.0 documentation
The Config object represents the configuration passed to the Alembic environment. From an API usage perspective, it is needed for the following use...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found