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

Flask won't start in the Python 3.4 debugger #1437

Closed
tomkcook opened this issue Apr 16, 2015 · 4 comments
Closed

Flask won't start in the Python 3.4 debugger #1437

tomkcook opened this issue Apr 16, 2015 · 4 comments

Comments

@tomkcook
Copy link

Test code:

import flask
app = flask.Flask()
app.run

Run like this:

$ pdb3 test.py
> /home/tkcook/scratch/python/test.py(1)<module>()
-> import flask
(Pdb) cont
Traceback (most recent call last):
  File "/usr/lib/python3.4/importlib/util.py", line 95, in find_spec
    spec = module.__spec__
AttributeError: 'module' object has no attribute '__spec__'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.4/pkgutil.py", line 481, in find_loader
    spec = importlib.util.find_spec(fullname)
  File "/usr/lib/python3.4/importlib/util.py", line 97, in find_spec
    raise ValueError('{}.__spec__ is not set'.format(name))
ValueError: __main__.__spec__ is not set

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3.4/pdb.py", line 1661, in main
    pdb._runscript(mainpyfile)
  File "/usr/lib/python3.4/pdb.py", line 1542, in _runscript
    self.run(statement)
  File "/usr/lib/python3.4/bdb.py", line 431, in run
    exec(cmd, globals, locals)
  File "<string>", line 1, in <module>
  File "/home/tkcook/scratch/python/test.py", line 1, in <module>
    import flask
  File "/usr/lib/python3/dist-packages/flask/app.py", line 331, in __init__
    instance_path = self.auto_find_instance_path()
  File "/usr/lib/python3/dist-packages/flask/app.py", line 622, in auto_find_instance_path
    prefix, package_path = find_package(self.import_name)
  File "/usr/lib/python3/dist-packages/flask/helpers.py", line 661, in find_package
    loader = pkgutil.get_loader(root_mod_name)
  File "/usr/lib/python3.4/pkgutil.py", line 467, in get_loader
    return find_loader(fullname)
  File "/usr/lib/python3.4/pkgutil.py", line 487, in find_loader
    raise ImportError(msg.format(fullname, type(ex), ex)) from ex
ImportError: Error while finding loader for '__main__' (<class 'ValueError'>: __main__.__spec__ is not set)
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
> /usr/lib/python3.4/pkgutil.py(487)find_loader()
-> raise ImportError(msg.format(fullname, type(ex), ex)) from ex

Is there a workaround for this?

@methane
Copy link
Contributor

methane commented Apr 16, 2015

Does it work on normal Python 3? (without PDB?)
Does it relate to #1011?

@tomkcook
Copy link
Author

It works on python3.4 without pdb. I'm not sure if it relates to #1011, though I'd guess so (it seems to be a very similar error in the same location).

@tomkcook
Copy link
Author

Yes, it is related to #1011 but not the same. On python3.4, the AttributeError doesn't get as far as helper.py:664 and it's necessary to catch ImportError instead. ie:

        root_mod_name = import_name.split('.')[0]
        try:
            loader = pkgutil.get_loader(root_mod_name)
        except (AttributeError, ImportError):
            loader = None

@brianrusso
Copy link

brianrusso commented May 22, 2017

Works fine on python 3.5.2 and 3.4.6 with pdb3

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants