0
votes

Config:

Ubuntu 16.04 LTS x64 
Apache/2.4.18
libapache2-mod-wsgi-py3  4.3.0-1.1build1 amd64
Python 3.4.6 (compiled from sources)
Pyramid running Python 3.4.6-based Virtualenv

myapp.wsgi file contains:

venv = '/path-to-venv/bin/activate_this.py'
exec(open(venv).read())
from pyramid.paster import get_app, setup_logging
...

Same result when enabling/disabling venv activation by code within myapp.wsgi, i.e. still crashing on 'from pyramid.paster...' line:

ImportError: No module named 'pyramid'

/etc/apache2/sites-available/myapp.conf:

    ServerName myapp.localhost
    DocumentRoot /path-to-myapp-project/

    WSGIApplicationGroup %{GLOBAL}

    WSGIPassAuthorization On

    WSGIDaemonProcess pyramid user=me group=me threads=4 \
            python-path=~/path-to-venv/lib/python3.4/site-packages

    WSGIScriptAlias / /path-to-myapp-project/myapp.wsgi

    <Directory /path-to-myapp-project/>
            WSGIProcessGroup pyramid
            Order deny,allow
            Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/myapp.localhost-error.log
    CustomLog ${APACHE_LOG_DIR}/myapp.localhost-access.log combined

Any tips ?

While trying to pip install mod_wsgi in a new virtualenv located outside my home dir, it crashes with:

/usr/bin/ld: /usr/bin/python3.4.6/lib/libpython3.4m.a(abstract.o): réadressage de R_X86_64_32S en vertu de « _Py_NotImplementedStruct » ne peut être utilisé lors de la création d'un objet partagé; recompilez avec -fPIC
/usr/bin/python3.4.6/lib/libpython3.4m.a : erreur lors de l'ajout de symboles : Mauvaise valeur
collect2: error: ld returned 1 exit status
error: command 'gcc' failed with exit status 1

----------------------------------------
Command "/anvenv/venv_py3.4.6/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-svro6spq/mod-wsgi/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-jfm8wwoj-record/install-record.txt --single-version-externally-managed --compile --install-headers /anvenv/venv_py3.4.6/include/site/python3.4/mod-wsgi" failed with error code 1 in /tmp/pip-build-svro6spq/mod-wsgi/
2
Read the mod_wsgi documentation on setting up use of a Python virtual environment. You are not doing it using the recommended method and you also can't use ~ in a path in Apache configuration. modwsgi.readthedocs.io/en/develop/user-guides/…Graham Dumpleton
@GrahamDumpleton Ok, have set up a python 3.4.6 venv out of home directory but can't pip install mod_wsgi from within it: error: command 'gcc' failed with exit status 1ting12
Unless can see the actual details of the error message from gcc, then can't really help you.Graham Dumpleton
@GrahamDumpleton Added details : do they mean I should recompile python 3.4.6 with '-fPIC' added to './configure' or 'sudo -H make install' ?ting12

2 Answers

0
votes

There's a tutorial Running a Pyramid Application under mod_wsgi in the Pyramid documentation that runs from start to finish.

0
votes

Your issue is a variation of:

and is caused by the fact that Python wasn't installed with a shared library.

You need to ensure that the --enable-shared option is supplied to the configure script for Python when it was being built from source code and installed.

For a bunch of other good practices around building Python from source code read:

It is about using Docker, but still relevant when building on your own system.