Debug Flask with complicated project structure

I'm new to debugging flask with pycharm, so hopefully nothing I ask is too trivial.

I have two files

code/ and code/

In the __init__ file is the where my Flask app is initialized meaning that is where the statement :

app = Flask(__name__) 


In the file is where I have the statement

if __name__ == '__main__':


The runserver imports the app in the following manner :

from code import app, __app_name__, __version__

Inside of the main function are a number of parser.addoption commands and then ultimately

def main():
parser = OptionParser()
    parser.add_option("-d","--debug",action="store_true",default=app.config.get('DEBUG',True),dest="debug",help="Turn on debugging")

(options,args) = parser.parse_args(),host=options.address,port=options.port)

In this case what would my entry point for debugging the application be?
I assumed it would be but when I attempt to debug this I get the response of

ImportError: No module named code

If however I run it like

   python ${BASE}/code/

I don't have any issue.
You need to upgrade to PyCharm 2.7.2 EAP ( and turn off the options for adding content roots and source roots to PYTHONPATH in the settings of the run configuration that you use to start your app. Alternatively, rename your project directory from "code" to something that does not match the name of a standard library module (
Thanks for your reply.

First my project directory was not actually named 'code' I had just listed it as that for sanitization purposes.

I'd prefer not too download the EAP for stability purposes.

One piece of information I forgot to include in my initial report was that I am running in a virtualenv. My issue seems to be identical to the one posted here :

I chose to add my 'code' directory as source in my project interpreter settings and that resolved my issue.

If I run across anything else I'll download the EAP

Please sign in to leave a comment.