mod_wsgi "Call to 'site.addsitedir()' failed" on AWS Elastic Beanstalk Python 3.6 platform
I encountered the same problem today ("64bit Amazon Linux 2017.09 v2.6.0 running Python 3.6", mod_wsgi errors).
I have a workaround, though I'm not sure it is a proper or the most direct solution.
In short
Install the latest mod_wsgi
.
Longer explanation...
Check it works manually
First I did the following manually to check it works, then I scripted it so it wouldn't be destroyed on a later deploy.
Installing mod_wsgi
will need apxs
, so go to the instance and find packages:
eb ssh
yum provides apxs
In my case there were 3. The oldest worked on the ssh console, so I added to .ebextensions/01_packages.config
:
packages:
yum:
...
httpd24-devel-2.4.27-3.75.amzn1.x86_64: []
Then in ssh I followed this sequence to test the manually built version od mod_wsgi
(I couldn't get any yum
package to work - though it can probably be done).
sudo -s # become root
cd /tmp
wget -q "https://github.com/GrahamDumpleton/mod_wsgi/archive/4.4.21.tar.gz"
tar -xzf '4.4.21.tar.gz'
cd ./mod_wsgi-4.4.21
./configure --with-python=/usr/bin/python3.6
make
make install
Assuming all is good so far, restart Apache:
service httpd restart
Then look in var/log/httpd/error_log
and hopefully you'll see:
... [pid 2088] AH00163: Apache/2.4.27 (Amazon) mod_wsgi/4.4.21 Python/3.6.2 configured -- resuming normal operations
I reloaded the Python app page and it's working (well it had a different error but mod_wsgi
is working).
Now to make this part of the deployment.
Scripting
After a few iterations, I settled on this in the .ebextensions/...
file:
packages:
yum:
git: []
gcc-c++: []
httpd24-devel-2.4.27-3.75.amzn1.x86_64: []
files:
"/tmp/update-wsgi.sh" :
mode: "000755"
owner: root
group: root
content: |
# update mod_wsgi
cd /tmp
wget -q "https://github.com/GrahamDumpleton/mod_wsgi/archive/4.4.21.tar.gz" && \
tar -xzf '4.4.21.tar.gz' && \
cd ./mod_wsgi-4.4.21 && \
sudo ./configure --with-python=/usr/bin/python3.6 && \
sudo make && \
sudo make install && \
sudo service httpd restart
commands:
mod_wsgi_update:
command: /tmp/update-wsgi.sh
cwd: /tmp
Some notes:
- the
gcc
dependency is needed formod_wsgi
to build - the
httpd24-devel
dependency is for theapsx
tool