WebFaction
Community site: login faq

I been following instructions here: http://flask.pocoo.org/snippets/65/

But some things aren't very clearly written.

So my structure is like this:

/<username>/webapps/flask/
----__init__.py
/<username>/webapps/flask/htdocs/
----index.py
----config.py
----/app/     (this is my flask application where i have views.py).
----/tmp/

My _init_.py:

class WebFactionMiddleware(object):
    def __init__(self, app):
        self.app = app
    def __call__(self, environ, start_response):
        environ['SCRIPT_NAME'] = '/app'
        return self.app(environ, start_response)

app.wsgi_app = WebFactionMiddleware(app.wsgi_app)

My index.py:

from flask import app as application

My httpd.conf:

WSGIPythonPath /home/<username>/webapps/flask/htdocs/
#If you do not specify the following directive the app *will* work but you will
#see index.py in the path of all URLs
WSGIScriptAlias /app /home/<username>/webapps/flask/htdocs/index.py

<Directory /home/<username>/webapps/flask/htdocs>
    AddHandler wsgi-script .py
    RewriteEngine on
    RewriteBase /app
    WSGIScriptReloading On
</Directory>

I installed from Control panel as "wsgi 3.4/Python2.7", but I had to install in SSH SQLAlchemy, flask-login, etc. using easy-install2.6 because easy-install2.7 doesn't exist.

Server error logs says:

 from flask import app as application
[Sun Nov 04 23:29:12 2012] [error] [client 127.0.0.1] ImportError: No module named flask

(I did restart apache2)

asked 04 Nov '12, 19:05

execute
726
accept rate: 0%

edited 04 Nov '12, 19:11


You need to find where the python module 'flask' is installed, likely in one of these 2 directories,

/home/<you>/lib/python2.7
/home/<you>/webapps/<your app>/lib/python2.7

Than add it to the WSGIPythonPath variable,

WSGIPythonPath /home/<username>/webapps/flask/htdocs/:/home/<username>/lib/python2.7:/home/<username>/webapps/flask/lib/python2.7/site-packages
permanent link

answered 04 Nov '12, 19:30

johns ♦♦
5.3k212
accept rate: 23%

@johns That doesn't exist. There is an apache2 under flask, in it, a lib folder, but it doesn't have anything in it. There is also no Python2.7 in /username/lib/... only Python2.6, but I installed wsgi3.4/Python2.7 when installing the app so I don't know why this happened. I also tried to install a Python2.7/wsgi 3.3 as well, to see if that does the trick, still no python2.7 folder visible.

(04 Nov '12, 23:34) execute

Did you install the python module for flask for python2.7? I just saw your note about

easy_install2.7

not existing, that is because it is

easy_install-2.7

try running this,

easy_install-2.7 flask
(05 Nov '12, 00:04) johns ♦♦

~> easy_install-2.7 flask

error: can't create or remove files in install directory

The following error occurred while trying to add or remove files in the installation directory:

[Errno 2] No such file or directory: '/home/<user>/lib/python2.7/test-easy-install-18761.pth'

The installation directory you specified (via --install-dir, --prefix, or the distutils default setting) was:

/home/<user>/lib/python2.7/

This directory does not currently exist. Please create it and try again, or choose a different installation directory (using the -d or --install-dir option).

(05 Nov '12, 01:14) execute

Yes, that error says "This directory does not currently exist. Please create it and try again", so you can do that. Just run:

mkdir $HOME/lib/python2.7

And try again.

(05 Nov '12, 03:44) ryans ♦♦

I see, I could not find that in any instructions. I assumed the error was wrong because I thought modwsgi3.4/Python2.7 module would automatically install python and create a python2.7 folder by itself. After I made that empty folder, easy_install started working, I didn't think it would just suddenly start working when you make an empty directory. But now I have a new error regarding index.py and TypeError: 'module' object is not callable. But thanks for solving this guys.

(05 Nov '12, 18:02) execute
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×52
×44
×7

question asked: 04 Nov '12, 19:05

question was seen: 5,598 times

last updated: 05 Nov '12, 18:02

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM