Reputation: 11
I am trying to make a website using Python(2.7), flask, apache2, mod_wsgi and an Enthought Canopy virtual environment (created using the canopy_cli
command line interface that comes with Canopy). I have done this before, and the live version on dreamhost appears to run fine with their passenger_wsgi shenanigans.
I am trying to make a development server on my old laptop at home. I have the venv set up the same way. I do not know what to insert into the WSGI file to make it use this virtual environment. For a normal virtual environment, in the env/bin/ directory there is an 'activate_this.py' script, but in a Canopy venv there is not.
On dreamhost, they suggest using this syntax in the wsgi file:
INTERP = os.path.join(os.environ['HOME'], 'project', 'env', 'bin', 'python')
if sys.executable != INTERP:
os.execl(INTERP, INTERP, *sys.argv)
sys.path.append(os.getcwd())
Which works fine in passenger_wsgi but when I run it on my dev server with mod_wsgi I get an error:
Premature end of script headers: dev.wsgi
/home/user/project/env/bin/python: can't open file 'mod_wsgi': [Errno 2] No such file or directory
So I suppose my choices are either to use virtualenv to make a normal virtual environment on the dev server(which would have an activate_this.py script which could be activated the normal way), or learn how to set up passenger_wsgi on my home machine.
That is, unless someone has done this before successfully and can tell me how to get a wsgi script/flask site to run in a Canopy virtual environment?
Upvotes: 1
Views: 418
Reputation: 58563
Go read:
The mod_wsgi module under Apache uses Python as an embedded system, it just doesn't make any sense to be doing os.execl(). Nor does using os.getcwd() make much sense either, as the working directory will not be where your source code is.
Anyway, read that link for how to setup virtual environments in Apache/mod_wsgi.
Upvotes: 2