2

I'm trying to install mod_wsgi on Raspbian Stretch Lite (which is based on Debian Stretch).

Following the documentation, I installed apache and mod_wsgi with:

sudo apt -y install apache2 apache2-dev
source ~/venv/bin/activate
pip3.6 install mod_wsgi

Everything looks good so far. To verify that the installation was successful, I ran

mod_wsgi-express start-server

But I got the error

apache2 (mod_wsgi-express): Syntax error on line 159 of /tmp/mod_wsgi-localhost:8000:1000/httpd.conf: Cannot load /home/pi/venv/lib/python3.6/site-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-arm-linux-gnueabihf.so into server: /home/pi/venv/lib/python3.6/site-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-arm-linux-gnueabihf.so: undefined symbol: forkpty

So what did I do wrong?

The mod_wsgi documentation has a section on the undefined forkpty error, but it only applies to Fedora and building mod_wsgi from source.

In case it's important, I installed Python 3.6 with:

sudo apt -y install build-essential checkinstall libbz2-dev libc6-dev libgdbm-dev libncursesw5-dev libreadline-gplv2-dev libsqlite3-dev libssl-dev openssl tk-dev zlib1g-dev
wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
tar xzvf Python-3.6.5.tgz
cd Python-3.6.5
./configure
make
sudo make altinstall
cd ..
sudo rm -r Python-3.6.5
rm Python-3.6.5.tgz
python3.6 -m venv ~/venv
source ~/venv/bin/activate
pip3.6 install --upgrade pip
pip3.6 install setuptools wheel
1

Workaround

I got it to work by installing from source. Note the --with-python option.

pip3.6 uninstall mod_wsgi
wget https://github.com/GrahamDumpleton/mod_wsgi/archive/4.6.4.tar.gz
tar xzvf 4.6.4.tar.gz
cd mod_wsgi-4.6.4
./configure --with-python=/usr/local/bin/python3.6
make
sudo make install
cd ..
sudo rm -r mod_wsgi-4.6.4
rm 4.6.4.tar.gz
echo "LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so" | sudo tee /etc/apache2/mods-available/wsgi.load
echo "LogLevel wsgi:info" | sudo tee /etc/apache2/mods-available/wsgi.conf
sudo a2enmod wsgi
sudo service apache2 restart

This doesn't provide the mod_wsgi-express command, but you do get a working installation.

Other Notes

  • As mentioned here, I tried adding LD_PRELOAD=/usr/lib/arm-linux-gnueabihf/libutil.so to the end of /etc/apache2/envvars, but this fix didn't work.
  • Using sudo apt install libapache2-mod-wsgi-py3 will only work with Python 3.5, not 3.6.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.