7

I'm trying to use uWSGI with a virtual env in order to use the Trac bug tracker on it.

I've installed system-wide uwsgi via pip.

Next, I've installed trac in a virtualenv

$ virtualenv venv
$ . venv/bin/activate
$ pip install trac

I've then written a simple uWSGI configuration script:

[uwsgi]
master = true
processes = 1
socket = localhost:3032

home = /srv/http/trac/venv/
no-site = true

gid = www-data
uid = www-data
env = TRAC_ENV=/srv/http/trac/projects/my_project
module = trac.web.main:dispatch_request

But when I try to launch it, it fails:

$ uwsgi --http :8000 --ini /etc/uwsgi/vassals-available/my_project.ini --gid www-data --uid www-data
...
Set PythonHome to /srv/http/trac/venv/
...
*** Operational MODE: single process ***
ImportError: No module named trac.web.main
unable to load app 0 (mountpoint='') (callable not found or import error)

I think uWSGI isn't using the virtual env. When inside the virtual env, I can import trac.web.main without having an ImportError.

How can I do that ? Thanks

Andrew Schulman
  • 8,561
  • 21
  • 31
  • 47
Nicolas Appriou
  • 173
  • 1
  • 1
  • 6

3 Answers3

14

Try adding this in your ini file:

plugins = python
virtualenv = /path/to/your/venv

You might also need router_basicauth to handle authentication.

Ladadadada
  • 25,847
  • 7
  • 57
  • 90
mda
  • 154
  • 3
  • 1
    For Python3 you need the `python3` plugin. On Ubuntu it can be installed with `apt install uwsgi-plugin-python3`. – kavinyao Aug 17 '20 at 04:47
2

To use the activated virtualenv you can use this config snippet in your uwsgi.ini:

; If VIRTAL_ENV is set then use its value to specify the virtualenv directory
if-env = VIRTUAL_ENV
virtualenv = %(_)
endif =
Beau
  • 287
  • 2
  • 11
0

Can tou try:

 which uwsgi

It tells which uwsgi command it uses to run your code. Make sure it is using uwsgi from your virtualenv, not from some system-wide installation.

Mikko Ohtamaa
  • 1,364
  • 3
  • 17
  • 28
  • 2
    As long as the uwsgi is complied for the correct python version, there's no reason you would want uwsgi "from your virtualenv" instead of system-wide. In fact, if you're using uwsgi from a venv instead of from OS packages, I'd suggest that's wrong. – Jason Antman Apr 11 '15 at 11:40
  • Unless when system wide uwsgi is an old version without an proper update. – jsbueno Feb 25 '16 at 12:31
  • @Mikko - I got access to a debian server which will run the system uwsgi (v`2.0.7-debian`) instead of the one configured on the virtualenv (`2.0.12`) regardless of what `which` returns, unless I hardcode the path on the shell ($/env/bin/uwsgi) - do you know about this bad behavior for uwsgi? – jsbueno Feb 25 '16 at 17:37
  • @jsbueno: I suggest you ask on the uWSGI mailing with details. – Mikko Ohtamaa Feb 25 '16 at 22:53