I'm trying to run a simple app on AWS AMI that should use OpenCV library. I created a virtual machine and i installed OpenCV. For the installation I followed this tutorial http://www.pyimagesearch.com/2015/06/22/install-opencv-3-0-and-python-2-7-on-ubuntu/ and seems to be ok also because I able to run the example. The problem arises when I try to run my Flask-app because I'm getting the following error:
[Tue Sep 20 09:58:14.117753 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] Traceback (most recent call last):
[Tue Sep 20 09:58:14.117778 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] File "/var/www/flaskapp/app.wsgi", line 25, in <module>
[Tue Sep 20 09:58:14.117822 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] from app import app as application
[Tue Sep 20 09:58:14.117831 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] File "/var/www/flaskapp/app.py", line 13, in <module>
[Tue Sep 20 09:58:14.117878 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] from flask import (Flask, abort, flash, g, jsonify, make_response, render_template, request, session, url_for)
[Tue Sep 20 09:58:14.117887 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] File "/var/www/flaskapp/env/lib/python2.7/site-packages/flask/__init__.py", line 19, in <module>
[Tue Sep 20 09:58:14.117916 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] from jinja2 import Markup, escape
[Tue Sep 20 09:58:14.117923 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] File "/var/www/flaskapp/env/lib/python2.7/site-packages/jinja2/__init__.py", line 33, in <module>
[Tue Sep 20 09:58:14.117951 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] from jinja2.environment import Environment, Template
[Tue Sep 20 09:58:14.117965 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] File "/var/www/flaskapp/env/lib/python2.7/site-packages/jinja2/environment.py", line 13, in <module>
[Tue Sep 20 09:58:14.118148 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] from jinja2 import nodes
[Tue Sep 20 09:58:14.118157 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] File "/var/www/flaskapp/env/lib/python2.7/site-packages/jinja2/nodes.py", line 19, in <module>
[Tue Sep 20 09:58:14.118287 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] from jinja2.utils import Markup
[Tue Sep 20 09:58:14.118296 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] File "/var/www/flaskapp/env/lib/python2.7/site-packages/jinja2/utils.py", line 531, in <module>
[Tue Sep 20 09:58:14.118418 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] from markupsafe import Markup, escape, soft_unicode
[Tue Sep 20 09:58:14.118436 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] ImportError: No module named markupsafe
but I checked all the installed modules on the virtual machine with the command pip freeze i get the following:
click==6.6
Flask==0.11.1
itsdangerous==0.24
Jinja2==2.8
MarkupSafe==0.23
numpy==1.11.1
Werkzeug==0.11.11
So MarkupSafe is installed and updated a the last version.
So started thinking the problem could be in my .wgsi file or in the httpd.conf
Here app.wsgi:
import sys
import site
import os
# Add virtualenv site packages
site.addsitedir(os.path.join(os.path.dirname(__file__), '/var/www/flaskapp/env/lib/python2.7/site-packages'))
#activate_this = '/var/www/flaskapp/env/bin/activate_this.py'
#execfile(activate_this, dict(__file__=activate_this))
# Path of execution
sys.path.insert(0,'/var/www/flaskapp')
#import the app
from app import app as application
And this one is the httpd.conf:
Listen 80
<VirtualHost *>
ServerName ec2...
WSGIDaemonProcess app threads=5 home=/var/www/flaskapp/ python-path=/var/www/flaskapp/env/lib/python2.7/site-packages threads=1
DocumentRoot /var/www/flaskapp
WSGIScriptAlias / /var/www/flaskapp/app.wsgi
<Directory /var/www/flaskapp>
WSGIProcessGroup app
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
But I'm not able to figure out the problem. Any idea about why I get this error?
If I try to reference my app.wgsi to lib64 instead of just lib the error becomes : ImportError: numpy.core.multiarray failed to import. I checked the differente site-packages present in lib and lib64 and I have this configuration:
lib :
click - easy_install.pyc - itsdangerous.py - markerlib - setuptools - click-6.6-py2.7.egg-info - flask - itsdangerous.pyc - pip - setuptools-12.0.5.dist-info - cv2.so - Flask-0.11.1.dist-info - jinja2 - pip-6.0.8.dist-info - werkzeug - easy_install.py - itsdangerous-0.24-py2.7.egg-info - Jinja2-2.8.dist-info - pkg_resources - Werkzeug-0.11.11.dist-info
while in lib64 I have:
markupsafe MarkupSafe-0.23-py2.7.egg-info numpy numpy-1.11.1-py2.7.egg-info
It seems the mod_wsgi is configured for python 2.6.9 and I'm using python 2.7. could that be the problem?
You cannot take a mod_wsgi compiled for Python 2.6 and try and force it to use a Python virtual environment using Python 2.7. You will need to uninstall mod_wsgi and reinstall it from a binary package or source, but where it is compiled for Python 2.7. It is not a configuration option to change what version of Python is used. It must be compiled for the correct Python version to start with.
Related
I have been trying to move a django project on my Linode server into production. After trying to use Apache and wsgi by following an online tutorial by Corey Schafer, I have encountered the following problem. I cannot for the life of my understand why this is happening, and have included error logs, my wsgi.py and my .conf file below.
[Tue Sep 29 23:20:35.753537 2020] [wsgi:error] [pid 143850:tid 140318623627008] [remote 90.214.108.58:50288] from django.core.wsgi import get_wsgi_application
[Tue Sep 29 23:20:35.753556 2020] [wsgi:error] [pid 143850:tid 140318623627008] [remote 90.214.108.58:50288] ModuleNotFoundError: No module named 'django'
[Tue Sep 29 23:28:18.507904 2020] [mpm_event:notice] [pid 143849:tid 140318652456000] AH00491: caught SIGTERM, shutting down
[Tue Sep 29 23:28:18.590367 2020] [mpm_event:notice] [pid 143989:tid 139664706964544] AH00489: Apache/2.4.41 (Ubuntu) mod_wsgi/4.6.8 Python/3.8 configured -- resuming normal operations
[Tue Sep 29 23:28:18.590439 2020] [core:notice] [pid 143989:tid 139664706964544] AH00094: Command line: '/usr/sbin/apache2'
[Tue Sep 29 23:28:24.089588 2020] [wsgi:error] [pid 143990:tid 139664678135552] [remote 90.214.108.58:50411] mod_wsgi (pid=143990): Failed to exec Python script file '/home/myname/projects/uw5-backend/u>
[Tue Sep 29 23:28:24.089643 2020] [wsgi:error] [pid 143990:tid 139664678135552] [remote 90.214.108.58:50411] mod_wsgi (pid=143990): Exception occurred processing WSGI script '/home/myname/projects/uw5-b>
[Tue Sep 29 23:28:24.095135 2020] [wsgi:error] [pid 143990:tid 139664678135552] [remote 90.214.108.58:50411] Traceback (most recent call last):
[Tue Sep 29 23:28:24.095172 2020] [wsgi:error] [pid 143990:tid 139664678135552] [remote 90.214.108.58:50411] File "/home/myname/projects/uw5-backend/uw5tables/wsgi.py", line 13, in <module>
[Tue Sep 29 23:28:24.095178 2020] [wsgi:error] [pid 143990:tid 139664678135552] [remote 90.214.108.58:50411] from django.core.wsgi import get_wsgi_application
[Tue Sep 29 23:28:24.095195 2020] [wsgi:error] [pid 143990:tid 139664678135552] [remote 90.214.108.58:50411] ModuleNotFoundError: No module named 'django'
wsgi.py
import os
import sys
from django.core.wsgi import get_wsgi_application
# add the hellodjango project path into the sys.path
sys.path.append('home/myname/projects/uw5-backend')
# add the virtualenv site-packages path to the sys.path
sys.path.append('home/myname/projects/uw5-backend/venv2/bin')
# poiting to the project settings
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'uw5tables.settings')
application = get_wsgi_application()
.conf
<Directory /home/myname/projects/uw5-backend/uw5tables>
<Files wsgi.py>
Order deny,allow
Require all granted
</Files>
</Directory>
WSGIScriptAlias / /home/myname/projects/uw5-backend/uw5tables/wsgi.py
WSGIDaemonProcess django_app python-path=/home/myname/projects/uw5-backend python-home=/home/myname/projects/uw5-backend/venv2
WSGIProcessGroup django_app
</VirtualHost>
I got the above error while using bitnami django.
All settings done according doc:
https://docs.bitnami.com/virtual-machine/components/django/#production
python version: Python 3.6.4 :: Anaconda, Inc.
django version: 2.0.2-3
wsgi.py:
import os,sys
sys.path.append('/Applications/djangostack-2.0.2-3/apps/django/django_projects/MyProject')
os.environ.setdefault("PYTHON_EGG_CACHE", "/Applications/djangostack-2.0.2-3/apps/django/django_projects/MyProject/egg_cache")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MyProject.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
httpd-app.conf:
<IfDefine !IS_DJANGOSTACK_LOADED>
Define IS_DJANGOSTACK_LOADED
WSGIDaemonProcess wsgi-djangostack processes=2 threads=15 display-name=%{GROUP}
</IfDefine>
<Directory "/Applications/djangostack-2.0.2-3/apps/django/django_projects/MyProject/MyProject">
Options +MultiViews
AllowOverride All
<IfVersion < 2.3 >
Order allow,deny
Allow from all
</IfVersion>
<IfVersion >= 2.3>
Require all granted
</IfVersion>
WSGIProcessGroup wsgi-djangostack
WSGIApplicationGroup %{GLOBAL}
Require all granted
</Directory>
Alias /MyProject/static "/Applications/djangostack-2.0.2-3/apps/django/lib/python3.6/site-packages/Django-2.0.2-py3.6.egg/django/contrib/admin/static"
WSGIScriptAlias /MyProject '/Applications/djangostack-2.0.2-3/apps/django/django_projects/MyProject/MyProject/wsgi.py'
httpd-prefix.conf:
# Include file
Include "/Applications/djangostack-2.0.2-3/apps/django/django_projects/MyProject/conf/httpd-app.conf"
corresponding url added to /Applications/djangostack-2.0.2-3/apache2/conf/bitnami/bitnami-apps-prefix.conf file
But when I'm trying to access app via browser I've got error in log:
[Fri Jun 22 16:37:20.873873 2018] [wsgi:error] [pid 29099] [remote ::1:62098] mod_wsgi (pid=29099): Target WSGI script '/Applications/djangostack-2.0.2-3/apps/django/django_projects/MyProject/MyProject/wsgi.py' cannot be loaded as Python module.
[Fri Jun 22 16:37:20.874027 2018] [wsgi:error] [pid 29099] [remote ::1:62098] mod_wsgi (pid=29099): Exception occurred processing WSGI script '/Applications/djangostack-2.0.2-3/apps/django/django_projects/MyProject/MyProject/wsgi.py'.
[Fri Jun 22 16:37:20.875482 2018] [wsgi:error] [pid 29099] [remote ::1:62098] Traceback (most recent call last):
[Fri Jun 22 16:37:20.875554 2018] [wsgi:error] [pid 29099] [remote ::1:62098] File "/Applications/djangostack-2.0.2-3/apps/django/django_projects/MyProject/MyProject/wsgi.py", line 17, in <module>
[Fri Jun 22 16:37:20.875568 2018] [wsgi:error] [pid 29099] [remote ::1:62098] application = get_wsgi_application()
[Fri Jun 22 16:37:20.875584 2018] [wsgi:error] [pid 29099] [remote ::1:62098] File "/Applications/djangostack-2.0.2-3/apps/django/lib/python3.6/site-packages/Django-2.0.2-py3.6.egg/django/core/wsgi.py", line 12, in get_wsgi_application
[Fri Jun 22 16:37:20.875594 2018] [wsgi:error] [pid 29099] [remote ::1:62098] django.setup(set_prefix=False)
[Fri Jun 22 16:37:20.875608 2018] [wsgi:error] [pid 29099] [remote ::1:62098] File "/Applications/djangostack-2.0.2-3/apps/django/lib/python3.6/site-packages/Django-2.0.2-py3.6.egg/django/__init__.py", line 24, in setup
[Fri Jun 22 16:37:20.875618 2018] [wsgi:error] [pid 29099] [remote ::1:62098] apps.populate(settings.INSTALLED_APPS)
[Fri Jun 22 16:37:20.875631 2018] [wsgi:error] [pid 29099] [remote ::1:62098] File "/Applications/djangostack-2.0.2-3/apps/django/lib/python3.6/site-packages/Django-2.0.2-py3.6.egg/django/apps/registry.py", line 89, in populate
[Fri Jun 22 16:37:20.875641 2018] [wsgi:error] [pid 29099] [remote ::1:62098] app_config = AppConfig.create(entry)
[Fri Jun 22 16:37:20.875654 2018] [wsgi:error] [pid 29099] [remote ::1:62098] File "/Applications/djangostack-2.0.2-3/apps/django/lib/python3.6/site-packages/Django-2.0.2-py3.6.egg/django/apps/config.py", line 90, in create
[Fri Jun 22 16:37:20.875664 2018] [wsgi:error] [pid 29099] [remote ::1:62098] module = import_module(entry)
[Fri Jun 22 16:37:20.875677 2018] [wsgi:error] [pid 29099] [remote ::1:62098] File "/Applications/djangostack-2.0.2-3/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
[Fri Jun 22 16:37:20.875687 2018] [wsgi:error] [pid 29099] [remote ::1:62098] return _bootstrap._gcd_import(name[level:], package, level)
[Fri Jun 22 16:37:20.875700 2018] [wsgi:error] [pid 29099] [remote ::1:62098] File "<frozen importlib._bootstrap>", line 994, in _gcd_import
[Fri Jun 22 16:37:20.875728 2018] [wsgi:error] [pid 29099] [remote ::1:62098] File "<frozen importlib._bootstrap>", line 971, in _find_and_load
[Fri Jun 22 16:37:20.875736 2018] [wsgi:error] [pid 29099] [remote ::1:62098] File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
[Fri Jun 22 16:37:20.875752 2018] [wsgi:error] [pid 29099] [remote ::1:62098] ModuleNotFoundError: No module named 'widget_tweaks'
I have installed widget_tweaks using:
pip3 install django-widget-tweaks
But when I stop Apache and run app using command
python3 manage.py runserver localhost:8080
the app works perfectly fine.
My urls.py under /Applications/djangostack-2.0.2-3/apps/django/django_projects/MyProject/MyProject look like:
from django.contrib import admin
from django.urls import path, include,re_path
urlpatterns = [
path('', include('APP.urls')),
re_path(r'^admin/', admin.site.urls, name='admin'),
]
So I assume error within Apache configuration. Any help or advises will be appreciated!
Thank you Jota for providing one of the solution.
Solution 1:
For Mac OS, when I execute /Applications/djangostack-2.0.2-3/use_djangostack, I enter Bitnami console.
I just had to install all the necessary modules and custom project ran successfully using apache.
Solution 2:
In case you don't wanna use bitnami console,
1) Install mod_wsgi using pip, preferably into a Python virtual environment. Ensure pip is for the version of Python you want to use.
pip install mod_wsgi
2) Display the config to add to Apache configuration file to load this mod_wsgi by running:
mod_wsgi-express module-config
3) Take the output of above command to display config and add to Apache configuration. (httpd.conf file)
4) restart the apache using ctlscript.sh file. In my case the command looked like:
/Applications/djangostack-2.0.2-3/ctlscript.sh restart apache
5) After restarting, my custom project ran successfully.
Regards,
Amey Kelekar
For a while now I have been trying to get my django project install of badgr (badgr-server on github) working with mod_wsgi. I am pretty way in over my head but I do believe I have made some progress. Here is the error message I am currently getting:
[Thu Nov 17 12:48:48.182772 2016] [core:notice] [pid 24556] AH00094: Command line: '/opt/rh/httpd24/root/usr/sbin/httpd'
[Thu Nov 17 12:48:50.421089 2016] [:error] [pid 24558] [remote 140.225.0.153:60440] mod_wsgi (pid=24558): Target WSGI script '/opt/badgr/code/apps/mainsite/wsgi.py' cannot be loaded as Python module.
[Thu Nov 17 12:48:50.421165 2016] [:error] [pid 24558] [remote 140.225.0.153:60440] mod_wsgi (pid=24558): Exception occurred processing WSGI script '/opt/badgr/code/apps/mainsite/wsgi.py'.
[Thu Nov 17 12:48:50.421200 2016] [:error] [pid 24558] [remote 140.225.0.153:60440] Traceback (most recent call last):
[Thu Nov 17 12:48:50.421228 2016] [:error] [pid 24558] [remote 140.225.0.153:60440] File "/opt/badgr/code/apps/mainsite/wsgi.py", line 27, in <module>
[Thu Nov 17 12:48:50.421348 2016] [:error] [pid 24558] [remote 140.225.0.153:60440] application = get_wsgi_application()
[Thu Nov 17 12:48:50.421374 2016] [:error] [pid 24558] [remote 140.225.0.153:60440] File "/opt/badgr/env/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
[Thu Nov 17 12:48:50.421450 2016] [:error] [pid 24558] [remote 140.225.0.153:60440] django.setup()
[Thu Nov 17 12:48:50.421472 2016] [:error] [pid 24558] [remote 140.225.0.153:60440] File "/opt/badgr/env/lib/python2.7/site-packages/django/__init__.py", line 20, in setup
[Thu Nov 17 12:48:50.421558 2016] [:error] [pid 24558] [remote 140.225.0.153:60440] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Thu Nov 17 12:48:50.421581 2016] [:error] [pid 24558] [remote 140.225.0.153:60440] File "/opt/badgr/env/lib/python2.7/site-packages/django/conf/__init__.py", line 46, in __getattr__
[Thu Nov 17 12:48:50.421705 2016] [:error] [pid 24558] [remote 140.225.0.153:60440] self._setup(name)
[Thu Nov 17 12:48:50.421728 2016] [:error] [pid 24558] [remote 140.225.0.153:60440] File "/opt/badgr/env/lib/python2.7/site-packages/django/conf/__init__.py", line 42, in _setup
[Thu Nov 17 12:48:50.421764 2016] [:error] [pid 24558] [remote 140.225.0.153:60440] self._wrapped = Settings(settings_module)
[Thu Nov 17 12:48:50.421782 2016] [:error] [pid 24558] [remote 140.225.0.153:60440] File "/opt/badgr/env/lib/python2.7/site-packages/django/conf/__init__.py", line 98, in __init__
[Thu Nov 17 12:48:50.421811 2016] [:error] [pid 24558] [remote 140.225.0.153:60440] % (self.SETTINGS_MODULE, e)
[Thu Nov 17 12:48:50.421841 2016] [:error] [pid 24558] [remote 140.225.0.153:60440] ImportError: Could not import settings 'settings' (Is it on sys.path? Is there an import error in the settings file?): No module named settings`
Here is a copy of my wsgi.py (/opt/badgr/code/apps/mainsite/wsgi.py):
"""
WSGI config for badgr project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/
"""
import sys
import os
import site
activate_this = os.path.expanduser("/opt/badgr/env/bin/activate_this.py")
execfile(activate_this, dict(__file__=activate_this))
path = '/opt/badgr/code/apps/mainsite'
if path not in sys.path:
sys.path.append(path)
os.environ["DJANGO_SETTINGS_MODULE"] = 'settings'
site.addsitedir('/opt/badgr/env/lib/python2.7/site-packages')
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
I am pretty sure my settings file is /opt/badgr/code/apps/mainsite/settings.py (or .pyc). But it seems to have trouble being called up.
Also it should be noted that I am running an env of Python 2.7:
/opt/badgr/env/lib/python2.7/
Finnally: Here is my django config in httpd24 (/opt/rh/httpd24/root/etc/httpd/conf.d/django.conf):
Alias /static /opt/badgr/code/staticfiles
<Directory /opt/badgr/code/staticfiles>
Require all granted
</Directory>
<Directory /opt/badgr/code/apps/mainsite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGISocketPrefix /var/run/wsgi/wsgi
WSGIDaemonProcess badgr
WSGIProcessGroup badgr
WSGIPythonPath /opt/badgr:/opt/badgr/env/lib/python2.7/site-packages
WSGIScriptAlias / /opt/badgr/code/apps/mainsite/wsgi.py
WSGIPythonHome /opt/badgr/env
Any help or assistance appreciated.
For the Apache configuration try using:
Alias /static /opt/badgr/code/staticfiles
<Directory /opt/badgr/code/staticfiles>
Require all granted
</Directory>
<Directory /opt/badgr/code/apps/mainsite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGISocketPrefix /var/run/wsgi/wsgi
WSGIRestrictEmbedded On
WSGIDaemonProcess badge python-home=/opt/badgr/env python-path=/opt/badgr/code/apps
WSGIProcessGroup badge
WSGIScriptAlias / /opt/badgr/code/apps/mainsite/wsgi.py
For the wsgi.py file revert it back to being similar to what was created originally.
import os
os.environ["DJANGO_SETTINGS_MODULE"] = 'mainsite.settings'
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
The WSGIRestrictEmbedded ensures only mod_wsgi daemon mode is used.
Set the location of the Python virtual environment using python-home option to WSGIDaemonProcess. Set the parent directory of your project in python-path. Change DJANGO_SETTINGS_MODULE to include the project name in module path again.
UPDATE 1
Add to the wsgi.py file:
import sys
print 'SYS.PATH = %r' % sys.path
Check the Apache error log to see what the path is and verify that the parent directory above where your project is, is listed.
The goal is to run Django in daemon mode on Apache via WSGI. I plan to run it on port 8000 to keep it separate from PHP files running at the root of server's URL (unless there's a better way to keep my web applications separate). It's setup with Virtualenv.
Server is named server.family.local
The simplified file structure is:
/home
/wwww
/django
/my_project
/app1
/app2
/project
wsgi.py
/env
/lib
/python3.5
/site-packages
The system runs properly when I activate the Virtualenv and use the manage.py file:
/home/www/django/my_project/manage.py runserver 0.0.0.0:8000
I'm trying to setup the WSGI on Apache so I don't have to manually run that command every time. My wsgi.py file consists of this:
import os
import sys
from django.core.wsgi import get_wsgi_application
sys.path.append('/home/www/django/my_project')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
application = get_wsgi_application()
The VirtualHost file for Apache, server_django.conf, has this:
<VirtualHost *:8000>
WSGIScriptAlias / /home/www/django/my_project/project/wsgi.py
WSGIProcessGroup my_project
WSGIDaemonProcess my_project python-path=/home/www/django/my_project/vision:/home/www/django/env/lib/python3.5/site-packages
Alias /static /home/www/django/my_project/project/static
<Directory /home/www/django/my_project/project/static>
Require all granted
</Directory>
<Directory /home/www/django/my_project/project>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
I've enabled the site using a2ensite. I checked that I have only libapache2-mod-wsgi-py3 installed (not libpache2-mod-python or libpache2-mod-wsgi). I think permissions are safe. Owner is my name but group is www, which is what Apache uses. The virtualenv directory has the same owner, group, and 775 permissions tag. The Python version could be an issue but I don't think it should be. When I'm in the virtualenv and run python -V, I get Python 3.5.1+. Outside the virtualenv, I get Python 2.7.12. My understanding is that this is why we use virtualenv - to isolate versions. So, if the Apache Virtual Host and the wsgi.py files are configured correctly, this shouldn't be the problem (I think).
When I try to reach my site at http://server.family.local:8000 I get a 500 Internal Server Error and find the following statements in the Apache error log.
[Wed Jul 27 22:56:05.850055 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] mod_wsgi (pid=1003): Target WSGI script '/home/www/django/my_project/project/wsgi.py' cannot be loaded as Python module.
[Wed Jul 27 22:56:05.850199 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] mod_wsgi (pid=1003): Exception occurred processing WSGI script '/home/www/django/my_project/project/wsgi.py'.
[Wed Jul 27 22:56:05.850645 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] Traceback (most recent call last):
[Wed Jul 27 22:56:05.850721 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] File "/home/www/django/my_project/project/wsgi.py", line 13, in <module>
[Wed Jul 27 22:56:05.850735 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] from django.core.wsgi import get_wsgi_application
[Wed Jul 27 22:56:05.850787 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] ImportError: No module named 'django'
[Wed Jul 27 22:56:06.062315 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] mod_wsgi (pid=1003): Target WSGI script '/home/www/django/my_project/project/wsgi.py' cannot be loaded as Python module.
[Wed Jul 27 22:56:06.062405 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] mod_wsgi (pid=1003): Exception occurred processing WSGI script '/home/www/django/my_project/project/wsgi.py'.
[Wed Jul 27 22:56:06.062573 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] Traceback (most recent call last):
[Wed Jul 27 22:56:06.062625 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] File "/home/www/django/my_project/project/wsgi.py", line 13, in <module>
[Wed Jul 27 22:56:06.062637 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] from django.core.wsgi import get_wsgi_application
[Wed Jul 27 22:56:06.062684 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] ImportError: No module named 'django'
[Wed Jul 27 22:56:06.467512 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] mod_wsgi (pid=1003): Target WSGI script '/home/www/django/my_project/project/wsgi.py' cannot be loaded as Python module.
[Wed Jul 27 22:56:06.467594 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] mod_wsgi (pid=1003): Exception occurred processing WSGI script '/home/www/django/my_project/project/wsgi.py'.
[Wed Jul 27 22:56:06.467757 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] Traceback (most recent call last):
[Wed Jul 27 22:56:06.467809 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] File "/home/www/django/my_project/project/wsgi.py", line 13, in <module>
[Wed Jul 27 22:56:06.467822 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] from django.core.wsgi import get_wsgi_application
[Wed Jul 27 22:56:06.467868 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] ImportError: No module named 'django'
[Wed Jul 27 22:56:06.658228 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] mod_wsgi (pid=1003): Target WSGI script '/home/www/django/my_project/project/wsgi.py' cannot be loaded as Python module.
[Wed Jul 27 22:56:06.658312 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] mod_wsgi (pid=1003): Exception occurred processing WSGI script '/home/www/django/my_project/project/wsgi.py'.
[Wed Jul 27 22:56:06.658476 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] Traceback (most recent call last):
[Wed Jul 27 22:56:06.658527 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] File "/home/www/django/my_project/project/wsgi.py", line 13, in <module>
[Wed Jul 27 22:56:06.658540 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] from django.core.wsgi import get_wsgi_application
[Wed Jul 27 22:56:06.658587 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] ImportError: No module named 'django'
I'm not an expert but seems that the problem starts with it's unable to load the wsgi.py file but I can't see why that would be any problem. Any help would be great. Thank you.
I've pushed my Flask app to ElasticBeanstalk but am getting 500 errors on every page and Target WSGI script '/opt/python/current/app/application.py' cannot be loaded as Python module. showing up in /var/log/httpd/error_log.
Here's the full stacktrace in /var/log/httpd/error_log:
[Wed Mar 18 22:02:36.815358 2015] [:error] [pid 21701] [remote 50.23.**2.10:0] mod_wsgi (pid=21701): Target WSGI script '/opt/python/current/app/application.py' cannot be loaded as Python module.
[Wed Mar 18 22:02:36.815389 2015] [:error] [pid 21701] [remote 50.23.**2.10:0] mod_wsgi (pid=21701): Exception occurred processing WSGI script '/opt/python/current/app/application.py'.
[Wed Mar 18 22:02:36.815410 2015] [:error] [pid 21701] [remote 50.23.**2.10:0] Traceback (most recent call last):
[Wed Mar 18 22:02:36.815435 2015] [:error] [pid 21701] [remote 50.23.**2.10:0] File "/opt/python/current/app/application.py", line 5, in <module>
[Wed Mar 18 22:02:36.815466 2015] [:error] [pid 21701] [remote 50.23.**2.10:0] from charts import *
[Wed Mar 18 22:02:36.815478 2015] [:error] [pid 21701] [remote 50.23.**2.10:0] File "/opt/python/current/app/charts.py", line 6, in <module>
[Wed Mar 18 22:02:36.815494 2015] [:error] [pid 21701] [remote 50.23.**2.10:0] from scipy.stats import linregress
[Wed Mar 18 22:02:36.815514 2015] [:error] [pid 21701] [remote 50.23.**2.10:0] ImportError: No module named scipy.stats
Here's what the first portion of my application.py looks like:
from flask import Flask, jsonify, request
import os
import logging
from logging import StreamHandler
from charts import *
application = app = Flask(__name__)
I'm assigning my flask app to the application object, which is all the docs say I need to do. Any clue what I'm doing wrong?
Thanks!