librelist archives

« back to archive

Problem debugging Flask under Python 3.3

Problem debugging Flask under Python 3.3

Eric Smith
2013-09-18 @ 16:34

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 

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\" --multiproc 
--client --port 58233 --file C:/dev/misc/flask/
pydev debugger: process 7044 is connecting

Connected to pydev debugger (build 129.782)
Traceback (most recent call last):
  File "C:\Python33_x64\Lib\", line 504, in find_loader
    return importlib.find_loader(fullname, path)
  File "C:\dev\misc\flask\env\lib\importlib\", 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\", line 1481, in <module>['file'], None, None)
  File "C:\Program Files (x86)\JetBrains\PyCharm 
2.7.3\helpers\pydev\", 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\", line 37, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc) #execute the script
  File "C:/dev/misc/flask/", line 4, in <module>
    app = Flask(__name__)
  File "C:\dev\misc\flask\env\lib\site-packages\flask\", line 331, 
in __init__
    instance_path = self.auto_find_instance_path()
  File "C:\dev\misc\flask\env\lib\site-packages\flask\", 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\", line 
661, in find_package
    loader = pkgutil.get_loader(root_mod_name)
  File "C:\Python33_x64\Lib\", line 482, in get_loader
    return find_loader(fullname)
  File "C:\Python33_x64\Lib\", 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

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?

Windows 7, Python 3.3.2, PyCharm 2.7.3, virtualenv.

(env) C:\dev\misc\flask>pip freeze

Eric Smith | Software Architect | StorageCraft Technology 
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.