Hello,
I am attempting to set up Trac using a virtualenv under mod_wsgi on Apache 
2.4.41.

I've run into a problem where I cannot get the Python script to run under 
the Python2.7 interpreter from the virtualenv. 

I am able to run Trac independent of Apache/WSGI so I think the problem 
lies in the WSGI configuration.


The paths referrred to below are:
/var/www/trac1.4 - Trac project environment
/var/www/trac1.4-venv - Python2.7 virtualenv with "trac" module installed 
via pip


Apache config:
------
WSGIPythonHome /var/www/trac1.4-venv

<VirtualHost *:80>

    ServerName trac.mydomain
    ServerAdmin webmaster@mydomain
    DocumentRoot /var/www/trac1.4/htdocs/
    WSGIDaemonProcess trac python-home=/var/www/trac1.4-venv
    WSGIScriptAlias / /var/www/trac1.4/site/cgi-bin/trac.wsgi 
    WSGIProcessGroup trac
    WSGIApplicationGroup %{GLOBAL}
</VirtualHost>
-------


The trac.wsgi script:
---------------
#!/var/www/trac1.4-venv/bin/python2.7
# -*- coding: utf-8 -*-
import os

import sys

# for testing:
print('sys.prefix       = %s' % repr(sys.prefix))
print('sys.path         = %s' % repr(sys.path))
print('sys.executable   = %s' % (sys.executable))
print('sys.version_info = %s.%s.%s' % (sys.version_info[0:3]))


def application(environ, start_request):
    if not 'trac.env_parent_dir' in environ:
        environ.setdefault('trac.env_path', '/var/www/trac1.4')
    if 'PYTHON_EGG_CACHE' in environ:
        os.environ['PYTHON_EGG_CACHE'] = environ['PYTHON_EGG_CACHE']
    elif 'trac.env_path' in environ:
        os.environ['PYTHON_EGG_CACHE'] = \
            os.path.join(environ['trac.env_path'], '.egg-cache')
    elif 'trac.env_parent_dir' in environ:
        os.environ['PYTHON_EGG_CACHE'] = \
            os.path.join(environ['trac.env_parent_dir'], '.egg-cache')
    from trac.web.main import dispatch_request
    return dispatch_request(environ, start_request)
---------------



Note what is logged when the script runs. Python V3.8.10 is the interpreter 
being used.
-----------------
[Tue Mar 22 12:32:40.155975 2022] [wsgi:error] [pid 1756932] sys.prefix     
  = '/var/www/trac1.4-venv'
[Tue Mar 22 12:32:40.156044 2022] [wsgi:error] [pid 1756932] sys.path       
  = ['/usr/lib/python38.zip', '/usr/lib/python3.8', 
'/usr/lib/python3.8/lib-dynload']
[Tue Mar 22 12:32:40.156072 2022] [wsgi:error] [pid 1756932] sys.executable 
  = /var/www/trac1.4-venv/bin/python
[Tue Mar 22 12:32:40.156100 2022] [wsgi:error] [pid 1756932] 
sys.version_info = 3.8.10


[Tue Mar 22 12:32:40.156527 2022] [wsgi:error] [pid 1756932] [remote 
10.130.176.220:48756] mod_wsgi (pid=1756932): Exception occurred processing 
WSGI script '/var/www/trac1.4/site/cgi-bin/trac.wsgi'.
[Tue Mar 22 12:32:40.165606 2022] [wsgi:error] [pid 1756932] [remote 
10.130.176.220:48756] Traceback (most recent call last):
[Tue Mar 22 12:32:40.165667 2022] [wsgi:error] [pid 1756932] [remote 
10.130.176.220:48756]   File "/var/www/trac1.4/site/cgi-bin/trac.wsgi", 
line 30, in application
[Tue Mar 22 12:32:40.165682 2022] [wsgi:error] [pid 1756932] [remote 
10.130.176.220:48756]     from trac.web.main import dispatch_request
[Tue Mar 22 12:32:40.165756 2022] [wsgi:error] [pid 1756932] [remote 
10.130.176.220:48756] ModuleNotFoundError: No module named 'trac'
-----------------


The virtualenv IS python2.7:
--------
me@rudin:~$ . /var/www/trac1.4-venv/bin/activate
(trac1.4-venv) me@rudin:~$ python -V
Python 2.7.18
--------

I'd really appreciate it if you could show me what I'm doing wrong.


-- 
You received this message because you are subscribed to the Google Groups 
"modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/modwsgi/8eb50796-0abb-4c92-9fd4-e8fa91d19ae6n%40googlegroups.com.

Reply via email to