Reputation: 31
First I followed the instructions in the tutorial on Matt Carrier's blog (although that assumed I would be making a subdirectory on my domain, when I'm not). Then I erased everything and started over with the instructions on the Dreamhost wiki page about Flask. Each time, I get a message in the browser reading: "An error occurred importing your passenger_wsgi.py". The answer for this topic on StackOverflow did not work for me.
My passenger_wsgi.py file is:
import sys, os
INTERP = os.path.join(os.environ['HOME'], 'flask_env', 'bin', 'python')
if sys.executable != INTERP:
os.execl(INTERP, INTERP, *sys.argv)
sys.path.append(os.getcwd())
from flask import Flask
application = Flask(__name__)
sys.path.append('penguicon-trax')
from penguicon-trax.penguicontrax import app as application
penguicon-trax is the name of the directory Git creates when I clone my app into the virtualenv where I installed Flask (not in the public dir). The app is penguicontrax.py without the dash.
I made sure the indent on the fourth line of passenger_wsgi.py was a tab, not spaces.
I used the DreamHost webpanel (where I'm fully hosted) to make /home/username/flask_env/public and I marked the "Passenger (Ruby/Python apps only)" checkbox and clicked the "Change Settings" button.
I FTP'ed passenger_wsgi.py directly into my flask_env directory on Dreamhost. When I SSH into Dreamhost, ls on the command line gives me:
bin lib passenger_wsgi.pyc public
include passenger_wsgi.py penguicon-trax
When I run passenger_wsgi.py through SSH, it gives me:
File "passenger_wsgi.py", line 11
from penguicon-trax.penguicontrax import app as application
^
SyntaxError: invalid syntax
It also does this when I just use "from penguicon-trax import app as application".
When I change that line to remove the dash: "penguicontrax.penguicontrax" and run it, it gives me "ImportError: No module named penguicontrax".
If I change the line to "from penguicontrax import app as application" and run it through SSH, it gives me no error message or other output. However, my domain now gives a 404.
Can you tell me what I'm doing wrong?
Upvotes: 1
Views: 2838
Reputation: 1937
If your passenger_wsgi.py has the following code at the end of it:
from foo.bar import app as application
... then you need a sub-directory named "foo" with two files in it: one file named bar.py
and another file named __init__.py
so that Python recognizes that the directory contains module code.
In your example, remove the dash from the folder name (penguicon-trax), since modules should have short, all-lowercase names. Then, your Flask application code would be in a file in $HOME/flask_env/penguicontrax/penguicontrax.py Lastly, run the following to try it out:
touch $HOME/flask_env/penguicontrax/__init__.py
python $HOME/flask_env/passenger_wsgi.py
Upvotes: 2