Just read again. You are using system package for mod_wsgi, not that installed 
for Anaconda. You should not be using both installs. Will send back 
instructions later when have time.

Graham

> On 9 May 2017, at 6:47 AM, Brian <[email protected]> wrote:
> 
> Thanks Graham. 
> 
> I did edit the FlaskApp.config file:
> <VirtualHost *:80>
>                 ServerName <public ip>.us-west-2.compute.amazonaws.com 
> <http://us-west-2.compute.amazonaws.com/>
>                 ServerAdmin ubuntu@ec2-<public 
> ip>.us-west-2.compute.amazonaws.com <http://us-west-2.compute.amazonaws.com/>
>                 WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi
>                 <Directory /var/www/FlaskApp/FlaskApp/>
>                         Order allow,deny
>                         Allow from all
>                 </Directory>
>                 Alias /static /var/www/FlaskApp/FlaskApp/static
>                 <Directory /var/www/FlaskApp/FlaskApp/static/>
>                         Order allow,deny
>                         Allow from all
>                 </Directory>
>                 WSGIDaemonProcess FlaskApp 
> python-path=/home/ubuntu/anaconda3/envs/test1.0/lib/python3.6/site-packages
>                 ErrorLog ${APACHE_LOG_DIR}/error.log
>                 LogLevel warn
>                 CustomLog ${APACHE_LOG_DIR}/access.log combined
> </VirtualHost>
> 
> And then applied following new step in the process:
> 
> ## get apache2
> sudo apt-get install apache2
> sudo apt-get install apache2-dev
> 
> ## get mod_wsgi
> #sudo apt-get install libapache2-mod-wsgi
> pip install mod_wsgi
> 
> ## force load Anaconda's shared library
> mod_wsgi-express module-config
> 
> ## enable mod_wsgi
> sudo a2enmod wsgi 
> 
> ## Install and register the mod_wsgi module with Apache  
> <--------------------------
> sudo `which mod_wsgi-express` install-module
> 
> ## get git 
> sudo apt-get install git
> 
> ## create apache config
> touch /etc/apache2/sites-available/FlaskApp.conf
> 
> ## disable default config
> sudo a2dissite 000-default
> 
> ## provide new config
> sudo a2ensite FlaskApp.conf
> 
> ## start/restart apache
> sudo service apache2 restart
> 
> The same error occurs in the log:
>  Traceback (most recent call last):
>    File "/var/www/FlaskApp/flaskapp.wsgi", line 7, in <module>
>      from FlaskApp import app as application
>    File "/var/www/FlaskApp/FlaskApp/__init__.py", line 1, in <module>
>      from flask import Flask
>  ImportError: No module named flask
> 
> Thoughts?
> 
> Best,
> -Brian
> On Monday, May 8, 2017 at 2:21:12 PM UTC-6, Graham Dumpleton wrote:
> Did you read:
> 
>     
> http://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html
>  
> <http://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html>
> 
> as I linked to.
> 
> There is no evidence that you have added anything for a Python virtual 
> environment if you are using one.
> 
> Graham
> 
>> On 9 May 2017, at 4:25 AM, Brian <the.lehm...@ <>gmail.com 
>> <http://gmail.com/>> wrote:
>> 
>> The conda environment must not be set correctly because it can't find flask:
>> 
>> [Mon May 08 16:39:11.002873 2017] [:error] [pid 31696:tid 139896253531904] 
>> [client 208.184.3.194:36413] Traceback (most recent call last):
>> 
>>  
>> 
>> [Mon May 08 16:39:11.002923 2017] [:error] [pid 31696:tid 139896253531904] 
>> [client 208.184.3.194:36413]   File "/var/www/FlaskApp/flaskapp.wsgi", line 
>> 7, in <module> 
>> 
>> [Mon May 08 16:39:11.002989 2017] [:error] [pid 31696:tid 139896253531904] 
>> [client 208.184.3.194:36413]     from FlaskApp import app as application 
>> 
>> [Mon May 08 16:39:11.003012 2017] [:error] [pid 31696:tid 139896253531904] 
>> [client 208.184.3.194:36413]   File 
>> "/var/www/FlaskApp/FlaskApp/__init__.py", line 1, in <module> 
>> 
>> [Mon May 08 16:39:11.003044 2017] [:error] [pid 31696:tid 139896253531904] 
>> [client 208.184.3.194:36413]     from flask import Flask 
>> 
>> [Mon May 08 16:39:11.003081 2017] [:error] [pid 31696:tid 139896253531904] 
>> [client 208.184.3.194:36413] ImportError: No module named flask
>> 
>> 
>> On Monday, May 8, 2017 at 11:45:31 AM UTC-6, Vanessa Marques wrote:
>> Brian, check out /var/log/apache2/error.log to see the errors and let us 
>> know what is in there. 
>> 
>> I'm having the exact same challenge as you (trying to configure flask + 
>> apache + anaconda + mod_wsgi on an ubuntu EC2 instance). 
>> 
>> On Monday, May 8, 2017 at 1:59:16 PM UTC-3, Brian wrote:
>> Thank you Graham. 
>> 
>> Any recs on testing and/or debugging a 500 internal server error when I try 
>> to hit the site? I'm assuming that it's in the configuration so I'm going to 
>> add full details of the process and config files below. 
>> 
>> All commands ran:
>> ## build conda environment
>> 
>> conda create --name test1.0 python==3.6.1 pandas jupyter requests flask
>> 
>> 
>> 
>> ## activate conda environment 
>> 
>> source activate test1.0
>> 
>>  
>> ## get apache2
>> 
>> sudo apt-get install apache2
>> 
>> sudo apt-get install apache2-dev
>> 
>> 
>> 
>> ## get mod_wsgi
>> 
>> #sudo apt-get install libapache2-mod-wsgi
>> 
>> pip install mod_wsgi
>> 
>> 
>> 
>> ## force load Anaconda's shared library
>> 
>> mod_wsgi-express module-config
>> 
>> 
>> 
>> ## enable mod_wsgi
>> 
>> sudo a2enmod wsgi 
>> 
>> 
>> 
>> ## get git 
>> 
>> sudo apt-get install git
>> 
>> 
>> 
>> ## create config for apache to know about wsgi and flask app
>> 
>> touch /etc/apache2/sites-available/FlaskApp.conf
>> 
>> 
>> 
>> ## disable default config
>> 
>> sudo a2dissite 000-default
>> 
>> 
>> 
>> ## provide new config
>> 
>> sudo a2ensite FlaskApp.conf
>> 
>> 
>> 
>> ## start/restart apache
>> 
>> sudo service apache2 restart
>> 
>> 
>> Contents of FlaskApp.conf:
>> <VirtualHost *:80>
>> 
>>                 ServerName <IPv4 PUBLIC IP>
>> 
>>                 ServerAdmin ubuntu@<IPv4 PUBLIC 
>> IP>.us-west-2.compute.amazonaws.com <http://us-west-2.compute.amazonaws.com/>
>>                 WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi
>> 
>>                 <Directory /var/www/FlaskApp/FlaskApp/>
>> 
>>                         Order allow,deny
>> 
>>                         Allow from all
>> 
>>                 </Directory>
>> 
>>                 Alias /static /var/www/FlaskApp/FlaskApp/static
>> 
>>                 <Directory /var/www/FlaskApp/FlaskApp/static/>
>> 
>>                         Order allow,deny
>> 
>>                         Allow from all
>> 
>>                 </Directory>
>> 
>>                 ErrorLog ${APACHE_LOG_DIR}/error.log
>> 
>>                 LogLevel warn
>> 
>>                 CustomLog ${APACHE_LOG_DIR}/access.log combined
>> 
>> </VirtualHost>
>> 
>> 
>> Location of flask app and .wsgi file.
>> (test1.0) ubuntu:/var/www$ tree
>> 
>> .
>> 
>> ├── FlaskApp
>> 
>>    ├── FlaskApp
>> 
>>    │   ├── __init__.py
>> 
>>    │   ├── static
>> 
>>    │   └── templates
>> 
>>    └── flaskapp.wsgi
>> 
>> 
>> Contents of flaskapp.wsgi:
>> #!/usr/bin/python
>> 
>> import sys
>> 
>> import logging
>> 
>> logging.basicConfig(stream=sys.stderr)
>> 
>> sys.path.insert(0,"/var/www/FlaskApp/")
>> 
>> 
>> 
>> from FlaskApp import app as application
>> 
>> application.secret_key = '<secret>'
>> 
>> 
>> Contents of __init__.py:
>> from flask import Flask
>> 
>> app = Flask(__name__)
>> 
>> @app.route("/")
>> 
>> def hello():
>> 
>>     return "Hello World (flask via conda env)!"
>> 
>> if __name__ == "__main__":
>> 
>>     app.run()
>> 
>> 
>> When visiting the site, I get a 500 internal server error. I likely messed 
>> up something with the config. Any help is greatly appreciated.
>> 
>> Best,
>> -Brian
>> 
>> On Sunday, May 7, 2017 at 6:32:18 PM UTC-6, Graham Dumpleton wrote:
>> In the first instance you should ensure things work with a WSGI hello world, 
>> no Flask framework. This ensures setup with Anaconda Python is okay, which 
>> sometimes doesn't always work because of stupid things Anaconda Python does 
>> which breaks the ability to use it in embedded systems.
>> 
>> As to deploying Flask, the Flask documentation has details:
>> 
>> * http://flask.pocoo.org/docs/0.12/deploying/mod_wsgi/ 
>> <http://flask.pocoo.org/docs/0.12/deploying/mod_wsgi/>
>> 
>> Also ensure you read:
>> 
>> * 
>> http://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html
>>  
>> <http://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html>
>> 
>> so you are setting up any Python virtual environment correctly as guides for 
>> frameworks often don't suggest the preferred method, or simply don't address 
>> it.
>> 
>> Graham
>> 
>>> On 7 May 2017, at 8:00 AM, Brian Lehman <[email protected] <>> wrote:
>>> 
>>> Thanks Graham. So everything is installed. Being brand new to this world, 
>>> I'm looking for a tutorial to (and please forgive me as I'm likely using 
>>> the wrong terminology) see how to tell Apache to use mod_wsgi to run my 
>>> flask app. I'm guessing that I need to change some config files in Apache 
>>> to use my conda environment and then write some .wsgi file? However, I'm 
>>> seeing quite a few different threads on this subject. Any advice is greatly 
>>> appreciated.   
>>> 
>>> ## get apache2
>>> sudo apt-get install apache2
>>> sudo apt-get install apache2-dev
>>> 
>>> ## get mod_wsgi
>>> pip install mod_wsgi
>>> 
>>> #force load Anaconda's shared library
>>> mod_wsgi-express module-config
>>> 
>>> ## start/restart apache
>>> sudo service apache2 restart 
>>> 
>>> On Thursday, May 4, 2017 at 4:22:08 PM UTC-6, Graham Dumpleton wrote:
>>> As per instructions in:
>>> 
>>>     https://pypi.python.org/pypi/mod_wsgi 
>>> <https://pypi.python.org/pypi/mod_wsgi>
>>> 
>>> You need to ensure you have the 'dev' packages for Apache installed.
>>> 
>>> If you are running Debian or Ubuntu Linux with Apache 2.4 system packages, 
>>> regardless of which Apache MPM is being used, you would need both:
>>> 
>>>     apache2
>>>     apache2-dev
>>> 
>>> Note that if using Anaconda Python, after having installed mod_wsgi with 
>>> pip, ensure you run:
>>> 
>>>     mod_wsgi-express module-config
>>> 
>>> to show the configuration you need to include in the system Apache if you 
>>> intend manually configuring it for mod_wsgi, instead of using 
>>> 'mod_wsgi-express start-server'.
>>> 
>>> This is necessary as Anaconda Python can require extra configuration 
>>> directives to force load its shared library. That command should output the 
>>> appropriate lines, although just check that the generated line for LoadFile 
>>> directive actually points at a valid path. Seen one report where for 
>>> Anaconda Python the path it generated was wrong and it had to be changed.
>>> 
>>> Graham
>>> 
>>>> On 5 May 2017, at 2:54 AM, Brian Lehman <the.lehm...@ <>gmail.com 
>>>> <http://gmail.com/>> wrote:
>>>> 
>>>> Good day. When I try to pip install mod_wsgi inside of an anaconda env 
>>>> called test1.0 on an aws ec2 instance w/ ubuntu, I get the folowing error. 
>>>> Any suggestions?
>>>> 
>>>> (test1.0) ubuntu$ python --version 
>>>> 
>>>> Python 3.6.1 :: Continuum Analytics, Inc.
>>>> 
>>>> (test1.0) ubuntu$ 
>>>> 
>>>> (test1.0) ubuntu$ 
>>>> 
>>>> (test1.0) ubuntu$ pip install mod_wsgi
>>>> 
>>>> Collecting mod_wsgi
>>>> 
>>>>   Using cached mod_wsgi-4.5.15.tar.gz
>>>> 
>>>>     Complete output from command python setup.py egg_info:
>>>> 
>>>>     Traceback (most recent call last):
>>>> 
>>>>       File "<string>", line 1, in <module>
>>>> 
>>>>       File "/tmp/pip-build-80walwu3/mod-wsgi/setup.py", line 164, in 
>>>> <module>
>>>> 
>>>>         'missing Apache httpd server packages.' % APXS)
>>>> 
>>>>     RuntimeError: The 'apxs' command appears not to be installed or is not 
>>>> executable. Please check the list of prerequisites in the documentation 
>>>> for this package and install any missing Apache httpd server packages.
>>>> 
>>>>     
>>>>     ----------------------------------------
>>>> 
>>>> Command "python setup.py egg_info" failed with error code 1 in 
>>>> /tmp/pip-build-80walwu3/mod-wsgi/
>>>> 
>>>> 
>>>> -- 
>>>> 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 modwsgi+u...@ <>googlegroups.com <http://googlegroups.com/>.
>>>> To post to this group, send email to mod...@ <>googlegroups.com 
>>>> <http://googlegroups.com/>.
>>>> Visit this group at https://groups.google.com/group/modwsgi 
>>>> <https://groups.google.com/group/modwsgi>.
>>>> For more options, visit https://groups.google.com/d/optout 
>>>> <https://groups.google.com/d/optout>.
>>> 
>>> 
>>> -- 
>>> 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 post to this group, send email to [email protected] <>.
>>> Visit this group at https://groups.google.com/group/modwsgi 
>>> <https://groups.google.com/group/modwsgi>.
>>> For more options, visit https://groups.google.com/d/optout 
>>> <https://groups.google.com/d/optout>.
>> 
>> 
>> -- 
>> 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 post to this group, send email to [email protected] <>.
>> Visit this group at https://groups.google.com/group/modwsgi 
>> <https://groups.google.com/group/modwsgi>.
>> For more options, visit https://groups.google.com/d/optout 
>> <https://groups.google.com/d/optout>.
> 
> 
> -- 
> 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] 
> <mailto:[email protected]>.
> To post to this group, send email to [email protected] 
> <mailto:[email protected]>.
> Visit this group at https://groups.google.com/group/modwsgi 
> <https://groups.google.com/group/modwsgi>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
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 post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.

Reply via email to