last day (14 days later) » 

1:39 PM
OK, let's figure this out. I know the docs need to be better, so this will help me too.
 
Alright, so I'm trying to run flask initdb from the official tutorial.
But I either get this:
Error: Failed to find application in module "cocktail_site".  Are you sure it contains a Flask application?  Maybe you wrapped it in a WSGI middleware or you are using a factory function.
Or ImportError: No module named 'cocktail_site.__init__.py'; 'cocktail_site.__init__' is not a package.
 
What's your tree?
 
C:.
│   setup.py
│   __init__.py
│
├───.idea
│   │   Cocktail Site.iml
│   │   encodings.xml
│   │   misc.xml
│   │   modules.xml
│   │   schema.sql
│   │   workspace.xml
│   │
│   └───dictionaries
│           mpthr.xml
│
├───cocktail_site
│   │   cocktails.db
│   │   cocktail_site.py
│   │   queries.py
│   │   schema.sql
│   │   __init__.py
│   │
│   ├───static
│   │       style.css
│   │
│   ├───templates
│   │       entry_detail.html
│   │       layout.html
│   │       login.html
│   │       show_entries.html
PYTHONPATH=C:\Python Workspace right now, which is where this is located.
I've tried the following values for FLASK_APP. cocktail_site, cocktail_site.__init__.py, cocktail_site.cocktail_site, and cocktail_site.cocktail_site.__init__.
 
Is there a Flask instance called app in __init__.py?
 
No.
Only in cocktail_site.py
Should it be in __init__? That seems super weird.
 
1:43 PM
The flask command only looks in exactly the import you point it at for something named app.
 
Then how come I can't do SET FLASK_APP=cocktail_site.py and have it look there?
 
So you could try FLASK_APP=cocktail_site.cocktail_site, or you could add from cocktail_site.cocktail_site import app in __init__.py.
 
I've tried the first one.
I just tried the second one and got this:
  File "C:\Python Workspace\cocktail_site\__init__.py", line 1, in <module>
    from cocktail_site.cocktail_site import app
ImportError: cannot import name 'app'
 
I don't think this will help, but remove the top level __init__.py, your project folder isn't a package.
 
Okay, done.
 
1:48 PM
cocktail_site is the package, and it contains a module called cocktail_site also, which is where app is.
 
Right.
 
Did you use setup.py to install the package in dev mode?
 
No. I'm not sure how.
 
OK, it's not strictly necessary.
Are you using a virtualenv?
 
Yeah.
 
1:51 PM
What does pip list say?
 
(COCKTA~1) C:\Python Workspace>pip list
click (6.6)
Flask (0.11.1)
itsdangerous (0.24)
Jinja2 (2.8)
MarkupSafe (0.23)
pip (8.1.2)
setuptools (26.0.0)
Werkzeug (0.11.10)
wheel (0.29.0)
 
Try FLASK_APP=cocktail_site/__init__.py, with app still imported in __init__
 
  File "c:\users\mpthr\cocktail site\lib\site-packages\flask\cli.py", line 89, in locate_app
    __import__(module)
ImportError: No module named 'cocktail_site/__init__'
 
Weird. I'm going to try to recreate what you have in a VM, I'll ping you in a couple minutes.
 
Okay. Thanks! Let me know if you need anything.
 
2:40 PM
I gotta run for an hour/hour and a half, but I'm semi available if you need any info.
Thanks again!
 
2:58 PM
@MorganThrapp are you using powershell or cmd?
I don't think set works for powershell, at least from this article: technet.microsoft.com/en-us/library/ff730964.aspx
That structure with set FLASK_APP=cocktail_site/__init__.py works fine for me in cmd, but not in powershell.
$env:FLASK_APP="cocktail_site/__init__.py"
 
3:38 PM
Cmd.
 
@MorganThrapp try a new terminal without setting PYTHONPATH, in your env, with what I showed above.
Make sure you use /, not .
Uh, maybe \ not / too. shakes fist at Windows
well, both work for me at least
 
Alright. I'll try when I get home. Just to be clear, my FLASK_APP should be as above, my Python path should be unset.
And what should my working directory be?
 
the directory containing the cocktail_site directory
 
The package? Or the module.
 
the package
 
3:48 PM
Okay. Thanks! I'll be home soon and I'll let you know.
 
4:09 PM
Woooo, it's working! Thanks!
 
4:30 PM
@MorganThrapp OK, so now I'm confused, what was different between then and now?
 
Honestly, I have no idea.
I restarted cmd.
Maybe that did it?
 
At least I learned that the instructions for powershell need to be slightly different.
 
The instructions in the docs also don't mention it needing to be app/__init__.py.
Or if they do, I missed it.
 
4:55 PM
That specific issue was fixed in the dev docs.
By wgwz, who shows up to the room occasionally.
 
Okay, cool.
 

last day (14 days later) »