librelist archives

« back to archive

Problem debugging Flask under Python 3.3

Problem debugging Flask under Python 3.3

From:
Eric Smith
Date:
2013-09-18 @ 16:34
Hi,

I know that Python 3.3 support is somewhat tentative, but allegedly 
working. I've run into a problem while trying to debug under PyCharm - not
sure if this is a Flask problem or just some side effect of how PyCharm 
debugs.

I'm just running the hello world example.

Python 2.7, no debugger: OK
Python 2.7, PyCharm debugger: OK
Python 3.3, no debugger: OK
Python 3.3., PyCharm debugger: Exception at startup. Here's the complete output:

C:\dev\misc\flask\env\Scripts\python.exe "C:\Program Files 
(x86)\JetBrains\PyCharm 2.7.3\helpers\pydev\pydevd.py" --multiproc 
--client 127.0.0.1 --port 58233 --file C:/dev/misc/flask/hello.py
pydev debugger: process 7044 is connecting

Connected to pydev debugger (build 129.782)
Traceback (most recent call last):
  File "C:\Python33_x64\Lib\pkgutil.py", line 504, in find_loader
    return importlib.find_loader(fullname, path)
  File "C:\dev\misc\flask\env\lib\importlib\__init__.py", line 64, in find_loader
    loader = sys.modules[name].__loader__
AttributeError: 'module' object has no attribute '__loader__'

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

Traceback (most recent call last):
  File "C:\Program Files (x86)\JetBrains\PyCharm 
2.7.3\helpers\pydev\pydevd.py", line 1481, in <module>
    debugger.run(setup['file'], None, None)
  File "C:\Program Files (x86)\JetBrains\PyCharm 
2.7.3\helpers\pydev\pydevd.py", line 1124, in run
    pydev_imports.execfile(file, globals, locals) #execute the script
  File "C:\Program Files (x86)\JetBrains\PyCharm 
2.7.3\helpers\pydev\_pydev_execfile.py", line 37, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc) #execute the script
  File "C:/dev/misc/flask/hello.py", line 4, in <module>
    app = Flask(__name__)
  File "C:\dev\misc\flask\env\lib\site-packages\flask\app.py", line 331, 
in __init__
    instance_path = self.auto_find_instance_path()
  File "C:\dev\misc\flask\env\lib\site-packages\flask\app.py", line 622, 
in auto_find_instance_path
    prefix, package_path = find_package(self.import_name)
  File "C:\dev\misc\flask\env\lib\site-packages\flask\helpers.py", line 
661, in find_package
    loader = pkgutil.get_loader(root_mod_name)
  File "C:\Python33_x64\Lib\pkgutil.py", line 482, in get_loader
    return find_loader(fullname)
  File "C:\Python33_x64\Lib\pkgutil.py", line 510, in find_loader
    raise ImportError(msg.format(fullname, type(ex), ex)) from ex
ImportError: Error while finding loader for '__main__' (<class 
'AttributeError'>: 'module' object has no attribute '__loader__')

Process finished with exit code 1


I can work around this by explicitly setting the instance path:

app = Flask(__name__, instance_path=r'C:\dev\misc\flask\instance')

It doesn't seem to matter if I pass in False for use_debugger and 
use_reloader in app.run.

I can log this as a bug on github if someone thinks this may really be a 
Flask bug (vs. a PyCharm bug). Any opinions? Does it seem like I'm doing 
something wrong?

Environment:
Windows 7, Python 3.3.2, PyCharm 2.7.3, virtualenv.

(env) C:\dev\misc\flask>pip freeze
Flask==0.10.1
Jinja2==2.7.1
MarkupSafe==0.18
Werkzeug==0.9.4
itsdangerous==0.23

Thanks,
Eric
________________________________
Eric Smith | Software Architect | StorageCraft Technology 
Corporation<http://www.storagecraft.com>
11850 Election Road Suite 100 | Draper | Utah | 84020
Office: 801.871.2797 | Fax: 801.545.4705
________________________________
If you are not the intended recipient of this message, be advised that any
dissemination or copying of this message is prohibited.
If you received this message erroneously, please notify the sender and 
delete it, together with any attachments.